• Post Reply Bookmark Topic Watch Topic
  • New Topic

Is the following right way to access bean?  RSS feed

 
Silu gill
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My servlet sets the property of Java Bean and my jsp page used <jsp:useBean> to access the bean after request dispatching. IS the right way?
Capture.PNG
[Thumbnail for Capture.PNG]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not any longer.

As of JSP 2 (introduced 10 years ago in 2002) <jsp:useBean> is no longer required to allow a scoped variable (usually a bean set in request scope) to be accessed via the EL (Expression Language).

Any use of Java code in a JSP has been discredited for a decade, and should never be used.
 
Silu gill
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Silu gill wrote:My servlet sets the property of Java Bean and my jsp page used <jsp:useBean> to access the bean after request dispatching. IS the right way?

Thanks Bear for quick moderation. I am struggling. I also used EL in the same code when you advised me to use EL, still I am not gettin anything. Thanks in advance.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some information on your setup and the code that you are using might be a tad helpful.
 
Silu gill
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Some information on your setup and the code that you are using might be a tad helpful.

Hi Bear, I am using Eclipse 3.5.0 and tomcate v6.0 server. Inside sr folder there are two packages: com.bean and com.test. Inside com.bean package there is java bean named Person.java and inside com.test there is TestServlet.java. TestServlet instatiates the Person class and sets the property , sets attributes and requestDispatches to Index.jsp . In web content I have one index.jsp file which tries to access bean using EL. It shows nothing. That means NPE(NullPointerException, right?) EL handles null pointer exception and does not show the error. I appreciate any brainstorming ideas. Thanks Bear.
 
Stefan Evans
Bartender
Posts: 1834
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is your servlet being executed? You can put a logging statement/debug break point in your servlet to see if that code is actually executing as you expect.

Have you got a servlet and servlet mapping declared in your web.xml for the application?
What url are you visiting to trigger the page? It should be the url of the servlet, rather than the JSP.




 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Silu gill wrote:TestServlet instatiates the Person class and sets the property , sets attributes and requestDispatches to Index.jsp .


Does that mean that it forwards the request, or that it redirects it? There is a significant difference. Using non-standard terminology when you describe your problem can be unhelpful.
 
Silu gill
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:
Silu gill wrote:TestServlet instatiates the Person class and sets the property , sets attributes and requestDispatches to Index.jsp .


Does that mean that it forwards the request, or that it redirects it? There is a significant difference. Using non-standard terminology when you describe your problem can be unhelpful.


Hello everyone, I would like to thank for your suggestion for diffrent perspective. Firstly, Bear had advised to use JSTL. Eventhough I am new to JSTL , friend of mine helped me to solve it using JSTL.
1. My set up was good. 2.Usebean did not work at all , I dont know why? 3. JSTL c:out worked after I instatiated the person bean into servlet and putting them into arraylist. again arraylist had to convert to array beucase JSTL c:out does not support arraylist. It is solved now.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Silu gill wrote:beucase JSTL c:out does not support arraylist. It is solved now.

Nonsense. The EL, which <c:out> depends upon, most certainly supports any List implementation.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!