• 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
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

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

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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....

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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><c:out value="${s.studentId}" /></td>
<td><c:out value="${s.studentName}" /></td>
<td><c:out value="${s.studentAge}" /></td>
<td><c:out value="${s.studentQualification}" /></td>
<td><c:out 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)
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in your tld file set rtexprvalueto true.

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?



 
Ranch Hand
Posts: 243
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
look! it's a bird! it's a plane! It's .... a teeny tiny ad
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!