File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp:getProperty / expression returns null

 
karthik chellappan
Ranch Hand
Posts: 31
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to do a simple example of UseBean Tag in JSP.

UserBean.java


firstAdditional.jsp:



secondAdditional.jsp:


thirdAdditional.jsp:


also tried using expression, which also returned null.


I'm not sure how to debug this. Please point out where i'm going wrong.
 
Stefan Evans
Bartender
Posts: 1640
9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You appear to be missing a quote in your input field around the name attribute:


With regards to debugging, Put some extra statements on your JSP page to test certain values.
I would recommend checking
- the request parameter being passed in (is the form value being submitted)
- the value in the bean (is the value being passed into the bean)
- the sesion id (are we maintaining the session)


On page 2, this code will see that the parameter is passing through correctly
And then check if your bean is being populated.

On page 3, the parameter should be null, the bean username should be populated, and the sessionid should be the same as the previous one.



 
karthik chellappan
Ranch Hand
Posts: 31
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Stefan.

Earlier i was getting 'The value for the useBean class attribute is invalid' error and on googling i got links which said that there should be a public default constructor without arguments in the java bean class. But for me issue was with class files not under WEB_INF directory.

Is it necessary that i include a public default constructor without arguments in the java bean class? As i see that above code runs fine without the constructor also.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64185
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
karthik chellappan wrote:issue was with class files not under WEB_INF directory.

WEB-INF, not WEB_INF.

Is it necessary that i include a public default constructor without arguments in the java bean class?

If there is no nullary constructor (one with no arguments), then it's not a bean, by definition.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic