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
 
Duplicated Session Variables 
 

We don't have any need to create a new session variable because it has been created by the JSP container for you.

 

Duplicated Session Variables

                          

We don't have any need to create a new session variable because it has been created by the JSP container for you. Now consider a case where you want to use the another variable by the same name, for e.g. we want to use "session"  for two times with the same name. Consider we have declared a session variable true in jsp page <%@ page session = "true"> and we want to use it again by using <% HttpSession session = request.getSession();%>. You will get an error saying "Duplication of local variable" because we can't declare a same variable twice.

Now consider a case we want to use the same variable name. At this situation we can solve this problem by using the <jsp: useBean> standard action tag.

The code of the program is given below:

package Mybean;
public class DuplicatedSessionJavaBean{
	private String name;
	private String pwd;
	private String email;
	public void setName(String name){
		this.name = name;
	}
	public String getName(){
		return name;
	}
	public void setPwd(String pwd){
		this.pwd = pwd;
	}
	public String getPwd(){
		return pwd;
	}
	public void setEmail(String email){
		this.email = email;
	}
	public String getEmail(){
		return email;
	}
}

 

<jsp:useBean id="duplicatedSession" class=
"Mybean.DuplicatedSessionJavaBean" scope="session"> <%-- The setProperty tag is only executed when a JavaBean is created --%> <jsp:setProperty name=
"duplicatedSession" property="name" value="James" /> <jsp:setProperty name=
"duplicatedSession" property="pwd" value="xyx" /> <jsp:setProperty name=
"duplicatedSession" property="email" value=" jamesbond@rediffmail.com" /> </jsp:useBean> <html> <head> <title>When a JavaBean already exists...</title> </head> <body> The username is :<jsp:getProperty name=" duplicatedSession" property="name" /><P> The password is :<jsp:getProperty name=" duplicatedSession" property="pwd" /><P> The email is :<jsp:getProperty name ="duplicatedSession" property="email" /><P>
    <a href="DuplicatedBean.jsp"><h1>Click
 </h1></a><br> to 
see another page that has the use <br> the same JavaBean with same name and scope. </body> </html>

 

<jsp:useBean id="duplicatedSession"   class="
Mybean.DuplicatedSessionJavaBean"
             scope="session" />
<html>
  <head>
    <title>When a JavaBean already exists...</title>
  </head>
  <body>
    <h1>Java Bean is already exist by this name and scope</h1>
    <P>
    The userName is :<jsp:getProperty 
name="duplicatedSession" property="name" /><P>
	The password is :<jsp:getPropert
y name="duplicatedSession" property="pwd" /><P>
	The email is    :<jsp:getPropert
y name="duplicatedSession" property="name" /><P>
  </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 

Current Comments

2 comments so far (
post your own) View All Comments Latest 10 Comments:

how to check two strings using struts tag in jsp page using session variable.

Posted by prabhu on Tuesday, 05.22.07 @ 11:42am | #16981

Does it mean that a new Session is automatically created by useBean tag plz reply

Posted by swathi on Saturday, 03.10.07 @ 11:57am | #11307

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.