Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Ashok
Session ID
2 Answer(s)      6 years and 4 months ago
Posted in : Java Beginners



Advertisement
View Answers

June 10, 2008 at 6:43 PM


Hi friend,

package javacode;

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

public class GetSession extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
HttpSession session = req.getSession(true);
res.setContentType("text/html");
PrintWriter out = res.getWriter();
String title = "Searching the Web";
String heading;
Integer count = new Integer(0);;
if (session.isNew()) {
heading = "Welcome, To GetID";
}
else {
heading = "Welcome Back";
Integer oldcount = (Integer)session.getValue("count");
if (oldcount != null) {
count = new Integer(oldcount.intValue() + 1);
}
}
session.putValue("count", count);
out.println(ServletValue.headWithTitle(title) +
"<body BGCOLOR=\"pink\">\n" +
"<h1 ALIGN=\"CENTER\">" + heading + "</h1>\n" +
"<center><H2>Information on Your Session:</H2></center>\n" +
"<TABLE BORDER=1 ALIGN=CENTER>\n" +
"<tr BGCOLOR=\"green\">\n" +
" <TH>Info Type<TH>Value\n" +
"<tr>\n" +
" <td><b>ID</b>\n" +
" <td>" + session.getId() + "\n" +
"<tr>\n" +
" <td><b>Creation Time</b>\n" +
" <td>" + new Date(session.getCreationTime()) + "\n" +
"<tr>\n" +
" <td><b>Time of Last Access</b>\n" +
" <td>" + new Date(session.getLastAccessedTime()) + "\n" +
"<tr>\n" +
" <td><b>Number of Previous Accesses</b>\n" +
" <td>" + count + "\n" +
"</table>\n" +
"</body></html>");

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

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


June 10, 2008 at 6:47 PM


package javacode;

import javax.servlet.*;
import javax.servlet.http.*;

public class ServletValue {
public static final String DOCTYPE =
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">";

public static String headWithTitle(String title) {
return(DOCTYPE + "\n" +
"<HTML>\n" +
"<HEAD><TITLE>" + title + "</TITLE></HEAD>\n");
}

public static int getIntParameter(HttpServletRequest request,
String paramName,
int defaultValue) {
String paramString = request.getParameter(paramName);
int paramValue;
try {
paramValue = Integer.parseInt(paramString);
} catch(NumberFormatException nfe) { // Handles null and bad format
paramValue = defaultValue;
}
return(paramValue);
}

public static String getCookieValue(Cookie[] cookies,
String cookieName,
String defaultValue) {
for(int i=0; i<cookies.length; i++) {
Cookie cookie = cookies[i];
if (cookieName.equals(cookie.getName()))
return(cookie.getValue());
}
return(defaultValue);
}

}

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

<servlet>
<servlet-name>getsession</servlet-name>
<servlet-class>javacode.GetSession</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>getsession</servlet-name>
<url-pattern>/jsp/GetSession</url-pattern>
</servlet-mapping>

---------------------------------------------
Read for more information.

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

Thanks


Related Tutorials/Questions & Answers:
Session ID
Session ID  How can I change the session ID of the page?   ...' session ID values because it is very likely to result in the loss of the session or with people acquiring other users' data. The session ID value should be managed
php maintain session id
php maintain session id   How to maintain session ID for a user in PHP
Advertisements
Session regenerated id
Session regenerated ID session_regenerate_id() works to regenerate the session... the session_regenrateid and set this id to new sessionid. <?php session_start..._id(); echo "Old Session:". $oldsessionid."<br />"
Session ID - Java Beginners
Session ID  Do we get new session id for a new domain after clicking..., IOException { HttpSession session = req.getSession(true... Session:\n" + "\n" + "\n
Printing Session Id Using Variable
Printing Session Id Using Variable  Hi, I am a learner in PHP language. Could any one guide me, how to print session Id using variable in PHP. Thanks
Usage of Session Id in servlet - Servlet Interview Questions
Usage of Session Id in servlet   Hi friends, I am beginner in servlets, without session Id can we do any operations like add,update,edit,delete. I saw Session id is loaded for edit and delete action not for add
Get Session Id
Get Session Id      ... the session id which was generated by the container.  HttpSession session.... There is no need to generate the unique session id. There is  no need to make
Get Session Id
Get Session Id      ... in understanding Get Session Id .In this example we import a package... the information of the user. The servlet include the class Get Session Id,Inside
Printing username,email Id using session variable.
Printing User Name, Email Id and Address using session variable Using $session() function, we can print user name, email id and address of the user. ...;address"];  echo "Your Email ID is ".$session_email."
How many ways can we get the value of current session id?
How many ways can we get the value of current session id?  How many ways can we get the value of current session id
id
id  how to find date of birth and gender in id in html with the help of javascript
session
session  is there any possibility to call one session from another session
session
session  is there any possibility to call one session from another session
Session
Session   how to session maintaining in servlet with use of hidden fieds
session
session  Session management in Java
Session
Session  How fined session is new or old
session
Session Management in PHP  Handling session in PHP. Can anyone please explain it with the help of an existing example about, how to handle a session while a user is logged in PHP
Session
Session   How can we set the inactivity period on a per-session basis?   We can set the session time out programmatically by using the method setMaxInactiveInterval() of HttpSession
session
session   explain sessioln tracking in jsp and display program
session
session  Which methods can be invoked by the container on a stateless session bean
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
Session
Session   hii, What Is a Session?   hello, Sessions are commonly used to store temporary data to allow multiple PHP pages to offer a complete functional transaction for the same visitor
session
session  how can transfer data of one page to another page using session in java swing
Session
Session  What Is a Session?   Hi friends, A session... subsequent HTTP requests. There is only one session object available to your PHP scripts at any time. Data saved to the session by a script can be retrieved
Session
;A servlet session is created and stored on the server side. The servlet container keeps.... To the maintain the session, Web clients must pass back a valid session.... In this sense, the session is also stored by the client, but only as a token reference
Session
Session   why do we need session? actually what stored in a session... and user would not able to retrieve the information. So, Session provides that facility to store information on server memory. 2)Variables are stored in session
session
session  how to implement login-logout session????   Please visit the following links: http://www.roseindia.net/quickguide/tomcat/Logout.shtml http://www.roseindia.net/jsp/javascriptpagerefresh.shtml http
total id
total id  how to print and total my id number ..for example if my id is 0123456789 the output will look like this : 0123456789 0+1+2+3+4+5+6+7+8+9=45 help me plz
<form id=
form id  sir, <form id="reg1" action="../UploadingCtrl" method="post" enctype="multipart/form-data" name="form1"> this action page can't get String tp = request.getParameter("indegrates"). i wrote article upload
<form id=
form id  sir, <form id="reg1" action="../UploadingCtrl" method="post" enctype="multipart/form-data" name="form1"> this action page can't get String tp = request.getParameter("indegrates"). i wrote article upload
id creation
id creation  CREATE TABLE mohan2 ( sno bigint(20) NOT NULL AUTO_INCREMENT, name varchar(30) NOT NULL, sal int(30) NOT NULL, eid varchar(30) NOT NULL, PRIMARY KEY (sno,eid) ) import java.sql.*; import
 

 

 

DMCA.com