aspose file tools*
The moose likes JSP and the fly likes how to get the value saved in request scope in a servlet into a jsp page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "how to get the value saved in request scope in a servlet into a jsp page" Watch "how to get the value saved in request scope in a servlet into a jsp page" New topic
Author

how to get the value saved in request scope in a servlet into a jsp page

santosh kimothi
Ranch Hand

Joined: Jun 10, 2009
Posts: 32
i saved some values in request scope in a servlet class.,,,

and i want to get that value in a jsp page....

can anybody tell me how to do this .........

its urgently needed....


Santosh Kimothi,
Java programmer
Prasanna Lakshmi
Greenhorn

Joined: Mar 24, 2009
Posts: 3
request is an implicit object in JSP page.

So, you can try out like this.

request.getAttribute("the name you have used in servlet class");

Eg:

In servlet class

Boolean flag=true;
In servlet class request.setAttribute("sessVariable", flag);

In JSP page;

Boolean value = (Boolean)request.getAttribute("sessVariable");

NOTE: whater type of Object you have set to request, while retrieving you have to do the casting of same type. otherwise, you will be getting ClassCastException.

Hope this will resolve you problem.



Thanks
Prasanna M
santosh kimothi
Ranch Hand

Joined: Jun 10, 2009
Posts: 32
thanks for your quick reply...... but my problem is still there..

i will specify my problem in detail...

i am having a servlet class as follows.... where i am saving the list(java.util.List) of records retrieved from db in a request scope...........

request.setAttribute(StudentConstants.STUDENT_LIST, studentList);

and in a jsp i want to display the contant of this list
and i am trying to do this....

<c:set var="s" value="${requestScope.StudentConstants.STUDENT_LIST)}" scope="request"></c:set>
<center>
<h1>Student Details</h1><br>
<table border="0" align="center">
<tr>
<td>Id</td><td>Name</td><td>Age</td><td>Quali</td><td>Course</td>
</tr>
<c:forEach var="s" items="${requestScope.studentlist}">
<tr>
<td><cut value="${s.studentId}" /></td>
<td><cut value="${s.studentName}" /></td>
<td><cut value="${s.studentAge}" /></td>
<td><cut value="${s.studentQualification}" /></td>
<td><cut value="${s.studentCourse}" /></td>
</tr>
</c:forEach>



but it is showing the following error message....
SEVERE: Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: /StudentDetails.jsp(3,0) According to TLD or attribute directive in tag file, attribute value does not accept any expressions
at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
Ramkumar Subburaj
Ranch Hand

Joined: Sep 07, 2007
Posts: 83
in your tld file set rtexprvalueto true.



SCJP 1.5, SCWCD 1.4.
Hanging between Web Services and EJB
Pedro Fracarolli
Greenhorn

Joined: Sep 03, 2008
Posts: 20
See, you're adding this attribute to your HttpServletRequest:



and you're accessing the attribute this way in your EL:



Excuse-me if I'm being ignorant, but shouldn't you actually need to use the value stored in the StudentConstants.STUDENT_LIST constant to retrieve the request attribute from the EL statement?



Srikkanth Mohanasundaram
Ranch Hand

Joined: Feb 07, 2007
Posts: 185
The problem lies in here



Please remove the ) character in the EL expression. And why do you need this value to be set in there ? (You can do away with this line of code).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to get the value saved in request scope in a servlet into a jsp page