| HTML Tutorials |
|
|
| XML Tutorials |
|
|
| Browser Scripting |
|
|
| Server Scripting |
|
|
| .NET (dotnet) |
|
|
| Multimedia |
|
|
| Web Building |
|
|
| Java Tutorials |
|
|
| Programming Langauges |
|
|
| Soft Skills |
|
|
|
-
Creating your second JSP page
-
JSP Sessions
|
|
Creating your second JSP page
|
The different tags which we have
learnt are using here. This example will declare two variables; one string used to stored the
name of a website and an integer called counter that displays the number of
times the page has been accessed. There is also a private method declared to
increment the counter. The website name and counter value are displayed.
|
|
<HTML>
<HEAD>
<!-- Example2 -->
<TITLE> JSP loop</TITLE>
</HEAD>
<BODY>
<font face=verdana color=darkblue>
JSP loop
<BR> <BR>
<%!
public String writeThis(int x)
{
String myText="";
for (int i = 1; i < x; i )
myText = myText "<font size=" i " color=darkred face=verdana>VisualBuilder
JSP Tutorial</font><br>" ;
return myText;
}
%> This is a loop example from the
<br>
<%= writeThis(8) %>
</font>
</BODY>
</HTML>
|
|
JSP Sessions
|
|
On any typical web site, a visitor might visit several pages and perform
several interactions.
If you are programming the site, it is very helpful to be able to associate some
data with each visitor. For this purpose, "session"s can be used in JSP.
A session is an object associated with a visitor. Data can be put in the session
and retrieved from it, much like a Hashtable. A different set of data is kept
for each visitor to the site.
Here is a set of pages that put a user's name in the session, and display it
elsewhere. Try out installing and using these.
First we have a form, let us call it GetName.html
|
<HTML>
<BODY>
<FORM METHOD=POST ACTION="SaveName.jsp">
What's your name? <INPUT TYPE=TEXT NAME=username SIZE=20>
<P><INPUT TYPE=SUBMIT>
</FORM>
</BODY>
</HTML>
|
|
The target of the form is "SaveName.jsp", which saves the user's name in
the session. Note the variable "session". This is another variable that is
normally made available in JSPs, just like out and request variables. (In the
@page directive, you can indicate that you do not need sessions, in which case
the "session" variable will not be made available.)
|
<%
String name = request.getParameter( "username" );
session.setAttribute( "theName", name );
%>
<HTML>
<BODY>
<A HREF="NextPage.jsp">Continue</A>
</BODY>
</HTML>
|
The SaveName.jsp saves the user's name in the session, and puts a link to
another page, NextPage.jsp.
NextPage.jsp shows how to retrieve the saved name.
|
<HTML>
<BODY>
Hello, <%= session.getAttribute( "theName" ) %>
</BODY>
</HTML>
|
If you bring up two different browsers (not different windows of the same
browser), or run two browsers from two different machines, you can put one name
in one browser and another name in another browser, and both names will be kept
track of.
The session is kept around until a timeout period. Then it is assumed the user
is no longer visiting the site, and the session is discarded.
|
Share And Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
 |
 |
Keywords: JSP Sessions,
session in jsp,
jsp session,
session setattribute,
session getattribute,
sessions in jsp,
servlet session,
session in servlet,
session tracking in jsp,
session in servlets,
session variable in jsp,
session tracking in servlets,
session management in jsp,
jsp source code,
session object in jsp,
request getparameter jsp,
session handling in jsp,
sessions in servlets,
jsp session object,
httpsession session,
servlets session,
session using jsp,
session tracking jsp,
servlet sessions,
servlet session tracking,
session variables in jsp,
session tracking in servlet
sessions jsp,
using session in jsp,
session timeout in jsp,
session management in servlets,
sessions in servlet,
example sessions in jsp,
jsp session handling,
servlet session management,
jsp session variable,
session attribute in jsp,
session time in jsp,
java servlet session,
jsp web xml
© 1999-2007 VisualBuilder.com - This article has been adapted from VisualBuilder.com.
|
|
| HTML Quizes |
|
|
| XML Quizes |
|
|
| Browser Scripting Quizes |
|
|
| Server Scripting Quizes |
|
|
| .NET (dotnet) Quizes |
|
|
| Multimedia Quizes |
|
|
| Web Building Quizes |
|
|
| Java Quizes |
|
|
| Programming Langauges Quizes |
|
|
| Soft Skills Quizes |
|
|
|