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