Session Tracking in servlet

Session Tracking in servlet

View Answers

January 30, 2009 at 4:32 AM

Hi friend,

1. URL rewritting:

package javacode;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class UrlRewrite extends HttpServlet {

public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, java.io.IOException {

res.setContentType("text/html");
java.io.PrintWriter out = res.getWriter();
String contextPath = req.getContextPath();
String encodedUrl = res.encodeURL(contextPath + "/default.jsp");

out.println("<html>");
out.println("<head>");
out.println("<title>URL Rewriter</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>This page will use URL rewriting if necessary</h2>");
out.println("Go to the default.jsp page <a href=\"" + encodedUrl + "\">here</a>.");
out.println("</body>");
out.println("</html>");

}

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, java.io.IOException {
doGet(request, response);

}
}

---------------------------

Web.xml

<servlet>

<servlet-name>urlRewrite</servlet-name>

<servlet-class>javacode.UrlRewrite</servlet-class>

</servlet>



<servlet-mapping>

<servlet-name>urlRewrite</servlet-name>

<url-pattern>jsp/UrlRewrite</url-pattern>

</servlet-mapping>

-----------------------------------------------

January 30, 2009 at 4:35 AM

Hidden Form Fields:

package javacode;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class HiddenFormDemo extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException {
PrintWriter out;
res.setContentType("text/html");
out = res.getWriter();
out.println("<html><head><title>Using hidden form In servlet</title></head>");
out.println("body");
String[] item = req.getParameterValues("item");
out.println("You currently have the item in your cart:");
if(items == null){
out.println("<b>None</b>");
}
else{
out.println("<ul>");
for(int i = 0; i < items.length; i++){
out.println("<li>" + items[i]);
}
out.println("</ul>");
}

out.println("<form Action=shopingcart method="POST">");
if(items ! = null){
for(int i=0; i< items.length; i++){
out.println("<input type="hidden" name="item" value=\"" + items[i] + "\">");
}
}
out.println("woulde you link to<br>");
out.println("<input type="submit" value="Add More Item">");
out.println("<input type="submit" value="Check out">");
out.println("</form>");
out.println("</body></html>");
}
}
-------------------------------------------------

web.xml

<servlet>

<servlet-name>hiddenFormDemo</servlet-name>

<servlet-class>javacode.HiddenFormDemo</servlet-class>

</servlet>



<servlet-mapping>

<servlet-name>hiddenFormDemo</servlet-name>

<url-pattern>jsp/HiddenFormDemo</url-pattern>

</servlet-mapping>

January 30, 2009 at 4:37 AM

Cookies:

package javacode;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class CookiesDemo extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException{
PrintWriter out;
response.setContentType("text/html");
out = response.getWriter();
Cookie cookie = new Cookie("CName","Cookie Value");
cookie.setMaxAge(100);
response.addCookie(cookie);

out.println("<HTML><HEAD><TITLE>");
out.println(" Use of cookie in servlet");
out.println("</TITLE></HEAD><BODY BGCOLOR='cyan'>");
out.println(" <b>This is a Cookie example</b>");
out.println("</BODY></HTML>");
out.close();
}
}

----------------------------------------------

web.xml

<servlet>

<servlet-name>cookiesDemo</servlet-name>

<servlet-class>javacode.CookiesDemo</servlet-class>

</servlet>



<servlet-mapping>

<servlet-name>cookiesDemo</servlet-name>

<url-pattern>jsp/CookiesDemo</url-pattern>

</servlet-mapping>


----------------------------------------------------

Visit for more information:

http://www.roseindia.net/servlets/

Thanks.

Amardeep









Related Tutorials/Questions & Answers:
session tracking - JSP-Servlet
  Hi friend, Session tracking is maintain the state of a user...session tracking  hi, i m working on a real estate web site....which i have to submit as final year project. im having problem regarding session
Servlet Session Tracking - JSP-Servlet
Servlet Session Tracking  Hi I have made a main page called... to a new Servlet of name: SessionNew by URL Redirecting method, but instead fo giving..."); PrintWriter pw = res.getWriter(); pw.println("Test Session Attributes
Advertisements
Session Tracking JSP - JSP-Servlet
Session Tracking JSP  Respected sir/madam, I am R.Ragavendran.. I Immediately need a coding for session tracking in JSP. Actually when the admin clicks "View Users logon status" Yiour coding must display the User Login
Session Tracking in servlet - Servlet Interview Questions
Session Tracking in servlet   Hi Friend, Can we use HttpSession for tracking a session or else 1.URL rewritting 2.Hidden Form...("Using hidden form In servlet"); out.println("body"); String[] item
problem without session tracking - JSP-Servlet
problem without session tracking  i want to see the code in which no session tracking has done and that is yielding the problem without session tracking   Hi friend, Please Give in Details to solve the problem
Session tracking
Session tracking  How can I enable session tracking for JSP pages if the browser has disabled cookies?   By default session tracking uses... not support cookies, or if cookies are disabled, you can still use session tracking
session tracking
session tracking  What are the common mechanisms used for session tracking?    Cookies SSL sessions URL- rewriting
Session Tracking Servlet Example
Session Tracking Servlet Example In this tutorial you will learn how to track session in servlet. Session tracking is required for identifying the client... client or the other when it tries to interact next time to the server. Session
Session tracking
Session tracking  What are the different ways for session tracking?    Cookies URL rewriting HttpSession Hidden form fields
session tracking
session tracking  What are the different ways for session tracking?   Cookies, URL rewriting, HttpSession, Hidden form fields
session tracking
session tracking  session tracking is of four type. 1.hidden form field 2.url rewriting 3.http session interface 4.cookies. please explan the third type with example
Session Tracking
Session Tracking  How Session Tracking ?   As we know that the Http is a stateless protocol, means that it can't persist the information.... Session Tracking can be done in three ways:ADS_TO_REPLACE_1 Hidden Form
session tracking - Ajax
session tracking  explain session tracking with example?  Hi friend, Session tracking is a mechanism that servlets use to maintain state... information about a shopping session, and each subsequent connection can
Session creation and tracking
Session creation and tracking  1.Implement the information persistence across servlet destroy or servlet container start/stop. Write a servlet such that when it is stopped (either by container shutdown or servlet stop
session tracking in jsp
session tracking in jsp  hi... i am creating 3 jsp pages ie. login.jsp,display.jsp,userinput.jsp.. i am able to pass the value from login.jsp to display.jsp using session set attribut ang get attribute.. but same ting
Servlet-session
Servlet-session  step by step example on session in servlets
Session tracking basics
. In session tracking client first make a request for any servlet, container... Session Tracking Basics       Session Tracking Session tracking is a process that servlets use
servlet session - JSP-Servlet
servlet session  how can i restrict number of users by 10 using... the counter if new user logs on and decrement if session times out or user  Hi... on and decrement if session times out or user log offs.Thanks
J2EE Tutorial - Session Tracking Example
J2EE Tutorial - Session Tracking Example... session-tracking feature. ( A stateless session bean does not retain ... and displayed, thereby achieving session-tracking.ADS_TO_REPLACE_19  
session concept - JSP-Servlet
session concept  Hello friends, How can we track unexpectedly closing a window when a jsp project running with session concept. And this tracking should update the log in status in data base
servlet session - JSP-Servlet
servlet session  hi, im working on a real estate web site.....n... login servlet fromabout us page now i want the servlet to redirect me... that called the servlet: like in JS we can call a previous page
Servlet Session
Servlet Session Sometimes it is required to maintain a number of request... between the client before invalidating this session by the servlet container.ADS... the session tracking by the application rewrite URLs, encodeURL(URL) method of response
session - JSP-Servlet
session  please send me an example code for session tracking using... that the Web server can't easily remember previous transactions.In session tracking.... There are four types of Session Tracking 1.Session 2.Cookies 3.Url-rewriting
jsp - session - JSP-Servlet
JSP - Session  How to manage session in JSP
Session removing - JSP-Servlet
Session removing  Hi, I am destroying session by using session.invalidate() in JSP but I am not able to destroy it completely can anyone help me... has been in session using session. setAttribute() but at log off I am using
Session Timeour - JSP-Servlet
Session Timeour  Hi, How to create a session timeout page in JSP? Session timeout should happen after 15 mins of idle instance. Thanks ...)to remove the session after 15 min(900 seconds). For more information, visit
session - JSP-Servlet
redirect the session  how i can redirect the session in any child window
Session tracking in login jsp program - JSP-Interview Questions
Session tracking in login jsp program  I have using jsp technology in my project.I want to do session tracking in my login form.After logout when i press back button it should be show session is expired.Please help me. Send
Session concept - JSP-Servlet
Session concept  Hai friends, I am doing a jsp project with session concept. If one person is not accessing his logged window for more than 10 minutes it gets automatically log out.Anybody explain me the reason
session - JSP-Servlet
session  How to manage session for a particular user ..using session management?  Answer:If you get id as a integer from mlid field then userid is set in your session.RegardsAmar  Answer:If you get id
session maintainence - JSP-Servlet
session maintainence  how to enable a link only if the form in previous page is clucked  please show me your code
arraylist with session - JSP-Servlet
arraylist with session  hi how can an arraylist stored in session.. and also how will it access?? pls give me the details with sample code..   Hi friend, Code to solve the problem : Thanks
session management - JSP-Servlet
session management  hi friends... hope u all dng fine. i am dng... think i am not using session management properly. and also in my web.xml file i said session timeout 1min. even it is also not working.wht to do :-( i will give
Usage of Session Id in servlet - Servlet Interview Questions
session in servlet For more details you can click: http://www.roseindia.net...Usage of Session Id in servlet   Hi friends, I am beginner in servlets, without session Id can we do any operations like add,update
Tracking User's Session using Hidden Form Fields
Tracking User's Session using Hidden Form Fields In this Section, We will discuss about tracking user's session using Hidden form field. Hidden Form Field is used to maintain the session. It is one of the method to handle
Tracking Session using URL rewriting
Tracking Session using URL rewriting In this section we will discuss about tracking user's session using URL rewriting using a simple example. For tracking sessions, we can use URL rewriting in place of cookies. Since http
java - JSP-Servlet
java  example of session tracking in servlet
session maintainence - JSP-Servlet
session maintainence  if the logout link is clicked in the main page it should display the message sucessfully logged out in the same page itself that is in the login page itself.say a way to solve this  Hi friend
get a session object - JSP-Servlet
get a session object  how to do in a table when i click on a radio button i should get the id value which is in the same row and store it in the session this is in jsp when in the servlet if i call a get session i have to get
session
session   explain sessioln tracking in jsp and display program
Keep servlet session alive - Development process
Keep servlet session alive  Hi, I am developing an application in java swing and servlet. Database is kept on server. I am using HttpClient for swing servlet communication. I want to send heartbeat message from client
Session Problem in JSP - JSP-Servlet
Session Problem in JSP  I have developed a online feedback form in JSP platform. I have created normal session in JSP page. It is running in my... then the session is not working. I have not used EJB. Please tell me how can I track session
Real time Mechanism fot Sessio Tracking - Servlet Interview Questions
Real time Mechanism fot Sessio Tracking   Hi Friends, Which is d most commonly used mechanism for tracking a session. and y it is best . thanks in advance
Session
Session   how to session maintaining in servlet with use of hidden fieds
session syntax for logout - JSP-Servlet
session syntax for logout  What is the syntax for writing session for logout page in login services ?  Hi friend<%@page import="java.util.*" %><%session.invalidate();%>You have logout. Please try
Session expire and back button in jsp and servlet .
Session expire and back button in jsp and servlet .  Hii Sir... to invalidate the session after a certain interval of time and after clicking logout button.Means that after session expiry time and logout action no one can access
calling a session bean bean from servlet using netbeans - EJB
calling a session bean from servlet using netbeans  How to call a session bean from servlet using netbeans in Java
How to implement session variables - JSP-Servlet
How to implement session variables  Hi, I have a servlet which gets parameter from a jsp page(x). it is stored in a variable in servlet as shown... session.getAttribute SERVLET: ------------------- HttpSession session = request.getSession
session
session  What mechanisms are used by a Servlet Container to maintain session information?   Servlet Container uses Cookies, URL rewriting, and HTTPS protocol information to maintain the session
how to make session timeout programatically - JSP-Servlet
how to make session timeout programatically  hi, i have a login page with username and password. how to make session timeout for 10minutes... to make session timeout programatically, you can use the method

Ads