| Author |
a question about bean
|
Niu Xiuyuan
Ranch Hand
Joined: Jun 08, 2001
Posts: 68
|
|
1.jsp <jsp:useBean id="str" class="java.lang.String" scope="session"/> <html> <body> <% str="hello"; %> <a href="2.jsp">click</a> </body> </html> 2.jsp <jsp:useBean id="str" class="java.lang.String" scope="session"/> <html> <body> <%=str%> </body> </html> I have two questions. 1.if i run 2.jsp first,i think the output should be null,that is because i have not set the variable str to any value,as the default it should be null.but in fact,it output nothing.why? 2.if i run 1.jsp first,then click the anchor,next the page will jump to 2.jsp,i think the output should be "hello",this is because i have set "hello" in the 1.jsp and the scope is session,so in 2.jsp the variable str have had the value of "hello",but in fact,the output is nothing,why? by the way,my web server is resin2.02.
|
Sun Certified Java Programmer<br />Sun Certified Web Component Developer
|
 |
ersin eser
Ranch Hand
Joined: Feb 22, 2001
Posts: 1072
|
|
<jsp:getProperty> <jsp:setProperty> HttpSeesion.getAttribute() did you read them ?
|
 |
Niu Xiuyuan
Ranch Hand
Joined: Jun 08, 2001
Posts: 68
|
|
i don't understand what your means? i think "<jsp:useBean.." create a instance which named by attribute "id" and its scope is set by "scope" attribute.so i can use the instance as common instance.
|
 |
Madhav Lakkapragada
Ranch Hand
Joined: Jun 03, 2000
Posts: 5040
|
|
I think the more fundamental thing is Can you use java.lang.String as a valid value for class attribute of the useBean tag? Acc to the Bean specs, I would say NO. It doesn't have the necessary getXX and setXX methods. So....thats what I think. - satya
|
Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
|
 |
Tao Liu
Greenhorn
Joined: Nov 02, 2001
Posts: 13
|
|
1. The output of 2.jsp is an empty string since "str" is created with the default constructor. 2. When the link is clicked in 1.jsp, the output of 2.jsp is still empty, which is also strange for me. "str" is a Session Bean, and it can pass info from page to page by getXX or setXX. The only thing I can find: "str" in <% str="hello"; %> is not "str" Bean, so it can't pass info from 1.jsp to 2.jsp. [ January 19, 2002: Message edited by: tao liu ]
|
 |
Carl Trusiak
Sheriff
Joined: Jun 13, 2000
Posts: 3340
|
|
|
Satya. As far as String being an appropriate bean, the spec require a no arguement constructor and a setXXX and getXX for Each property you wish to access through getProperty and setProperty. Since this page didn't call setProperty or getProperty, String is a valid JSP Bean.
|
I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
|
 |
Madhav Lakkapragada
Ranch Hand
Joined: Jun 03, 2000
Posts: 5040
|
|
Since this page didn't call setProperty or getProperty, String is a valid JSP Bean OOPS, my bad!!! Thanks, Carl. - satya
|
 |
 |
|
|
subject: a question about bean
|
|
|