Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials:
 

Software Solutions and Services
 

 
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments
 
Preventing the creation of a Session in a Jsp Page 
 

In jsp we have been provided the implicit session object. In jsp the session is by default true, if we don't declare a session = "true" inside the directive, then the session is still available as it is by default true.

 

Preventing the creation of a Session in a Jsp Page

                          

In jsp we have been provided the implicit session object. In jsp the session is by default true, if we don't declare a session =  "true" inside the directive, then the session is still available as it is by default true. There is not any such use to declare a session false, but to learn just imagine if we declare a session = "false", then what will happen. 

For check this make one jsp page or html page where we have given two field, one is of name and the second one is of password. Now make  a controller which will control the request and response object. Declare the session as false in the page, it will be declared inside the directive. We will try to retrieve the values of the field by using the request.getParameter(), request is the implicit object which has been provided to us by the jsp and the getParameter() is the method of request object. We can see that by declaring the session as false the values will not be able to retrieved by the controller. It will throw a exception.

The code of the program is given below:

<html>
	<head>
		<title>Welcome </title>
	</head>
	<body>
		<form method = "post" action = "SessionLess.jsp">
			<font size = 6>Enter your name<input type = 
"text" name = "name"></font><br><br> <font size = 6>Enter your password<input type=
"password" name = "pwd" ></font><br><br> <input type = "submit" name = "submit" value = "submit" > </form> </body> </html>

 

<%@ page session="false"%>
<%  
    String name = request.getParameter("name");
	String password = request.getParameter("pwd");
	if(name.equals("Williams") && password.equals("abcde"))
	{
		session.setAttribute("username",name);
		response.sendRedirect("NextPageOfSessionLess.jsp");
	}
	else
	{
		response.sendRedirect("NoSession.html");
	}
	%>

 

<html>
<head>
<title>Welcome in In the program session</title>
</head>
<body>
<font size = 6>Hello</font> <%= session.getAttribute("username") %>
</body>
</html>

The output of the program is given below:

Download this example.


 

                          

» View all related tutorials
Related Tags: java c web com ide session data application io module copy help sessions sed output vi value using this id

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Website Designing Services
 
Web Designing Packages From $150!
 
Website Designing Company Web Hosting
 
Website Designing Quotation
 
Search Tutorials:

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.