Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML


 
  
 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 

 
Facing Programming Problem?
Ask Questions?, Browse Latest Questions, Question-Answer Guidelines
JSP
  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. 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.


 

                          

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

Latest Searches:
break��?��?�
core java
round
jsp with servlet code
breakÑ?â??â??Ñ?â???Ñ?â
coding of radio button
convert string to stin
unix
count the number of di
Linked List C
flow of file uploading
matches()
ColdFusion Development
server
File
settext
displaying images usin
FlowLayout
viewing content in a f
Ajax Login Example
Photoshop Northern Lig
downloading images usi
string array add eleme
dynavalidatorform
jsp login validation a
source code for chat p
jasper reports using j
max length 500 chars
project on eclipse usi
set cell value JTable
rmi
Database MySQL Using S
Photoshop Web Graphics
compare two arraylist
Copy one or more files
struts-nested select
xslt
ResourceBundle
session remove attribu
retrieving images usin
if-else-then
jQuery to text changes
getId
hibernate associations
struts DAO connection
ResourceBundle in jsp
java: read string arra
ASP Database Related A
webservices soap
create file menu using
javaதà¯?�??தà¯?ï
pseudocode
�����?��
Insert an array list o
Murachநà¯??பà¯???à
help
validate radio button
Photoshop Effects Real
file uploading code us
jsp call servlet
Scala Plugin
Copy One Database Tabl
struts select
java arrays
check character
Eclipse 3.4 EJB
scalar
how to arrange strings
date validation in jav
jsp MENU SELECT MAKES
inserting records of r
Use of <fn:substringBe
Java date format
java application code
sample program for mar
how to disable the tex
blinking text
Ñ?одÑ?п?Ñ?о???Ñ?о
The Jakarta-Taglibs: D
conditionally hide tab
Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

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 | 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.