Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

a question about bean

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1072
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<jsp:getProperty>
<jsp:setProperty>
HttpSeesion.getAttribute()
did you read them ?
 
Niu Xiuyuan
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Since this page didn't call setProperty or getProperty, String is a valid JSP Bean

OOPS, my bad!!!
Thanks, Carl.
- satya
 
Get me the mayor's office! I need to tell him about this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic