File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes How to store bean data into a JSP variable? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "How to store bean data into a JSP variable?" Watch "How to store bean data into a JSP variable?" New topic
Author

How to store bean data into a JSP variable?

Ray Udo
Greenhorn

Joined: Sep 27, 2005
Posts: 9
Hi friends,

I have a problem...I'm stuck on jsp/bean manipulation.
Details:
=======
I am trying to read data sent from a bean and store it in the jsp page for use in immediate processing. I have been reading a lot of jsp sample codes on the sun site as well as Sam's teach yourself j2ee in 21 days and so far my assessment is that either I am being forced to use JSTLs most times or else what the samples are demonstrating is rudimentary. All I want to do is take data from a bean, store it to a variable declared within the scope of the jsp request or session. Could anyone give me a sample working code demonstrating data storage where data is being retrieved from a request/response combination into a JSP page declared variable?

My Non-working Code:
===================
<jsp:useBean id="indexbean" scope="request" class="loginmodule.IndexBean" />
...
<jsp:setProperty name="IndexBean" property="*" />
<-- trying to get status of database query into variable Status -->
<%! String Status= null;%>
<%
Status = ((String)request.getAttribute("STATUS")).getStatus();
-- "STATUS" is the String variable in the bean which stores the status
if (Status != null)
response.sendRedirect("http://localhost:8081/SOFTWARE/menu.html");
else
response.sendRedirect("http://localhost:8081:/SOFTWARE/ErrorPg.html");
%>
...
<-- Also tried using code: Status = mypackage.IndexBean.getSTATUS(); -->

Output:
======
I can not even get it to compile, but what happens is that if I sit there and click on the go button after three of four clicks it displays and then when I hit the form button, it says --
"An error occurred at line: 52 in the jsp file: /index.jsp
Generated servlet error:
The method getStatus() is undefined for the type String"

Any help is greatly appreciated,
Ray
Praful Thakare
Ranch Hand

Joined: Feb 10, 2001
Posts: 627
Hi Ray,

From the information you have provided I can guess you have class called loginmodule.IndexBean and it has method called getSTATUS() and this bean is stored in request scope with attribute named as STATUS,if this is correct then try the following




Warm Regards
-Praful
[ March 31, 2006: Message edited by: Praful Thakare ]

All desirable things in life are either illegal, banned, expensive or married to someone else !!!
Ray Udo
Greenhorn

Joined: Sep 27, 2005
Posts: 9
Thank you Praful,

You were right about your assumptions about my code. However, when I execute the code below...

Status = ((loginmodule.IndexBean)request.getAttribute("STATUS")).getStatus();

It still gives me the same error message:
"An error occurred at line: 92 in the jsp file: /NewUser.jsp
Generated servlet error:
The method getStatus() is undefined for the type IndexBean"

Any more ideas?

Thanks guys,
Ray
Ray Udo
Greenhorn

Joined: Sep 27, 2005
Posts: 9
Sorry Praful,

My apologies, that was a working code, just put it in the wrong jsp file. But, I am still not able to get the desired results.

All I want to do is get info from a jsp page write to database using beans and then use the status of the query to go to the next link.

I could use some more help friends,
Ray
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to store bean data into a JSP variable?