• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to Get a String attribute from Request Using EL?

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi friends,

My Problem is how to get a String value from EL?
for Example:
in servlet class:

public class sample extends HttpServlet {

public void doGet(HttpServletRequest request , HttpServletResponse response) throws IOException, ServletException {

request.setAttribute("String1", "Hello") ;
RequestDispatcher rd = request.getRequestDispatcher("/sample.jsp") ;
rd.forward(request, response) ;

}
}

in Sample.jsp
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<body>
<c:out value= "${String1}"/>
<c:out value= "${requestScope.String1}"/>
<c:out value= "${requestScope.request.String1}"/>
${String1}

In above Codes are return with EL syntax (e.g ${requestScope.String1}) I cant able to get the value

but if i use scriptlets means, I can

Can you Help out this problem?

Note:
I want to use EL only
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try this :

<c:out value= "${pageContext.request.String1}"/>
 
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you can use
in scriptlet

out.println(request.getAttribute("String1");
 
vijayakumar durai
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you can use wihtout scriptlet

"${param.String1}"
 
Kathiresan Chinnasamy
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you friends,

I got it
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Kathiresan Chinnasamy:
Thank you friends,

I got it

Please post how you resolved the problem as most of the asnwers you've been given so far are either unnecessary, or wrong.
 
Ranch Hand
Posts: 153
Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Today I had the same problem as posted by Kathiresan and I have resolved this one as

1) in servlet I am setting
request.setAttribute("reviewCommnts", comments);
then forward the request to jsp2

2) in jsp2.jsp
I got the value in two ways both are working
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c_rt" %>

With JSTL <c_rt:out value="${requestScope.reviewCommnts}"></c_rt:out>
Review Comment only with expresssion language ${requestScope.reviewCommnts}

Hope that helps to somebody

[EDIT: removed unnecessary code tags]
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Malatesh Karabisti wrote:<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c_rt" %>


Why are you using such an ancient version of the JSTL?

Unless you are still stuck using an antiquated container such as Tomcat 4, you should be using a more modern version of the JSTL.
 
clojure forum advocate
Posts: 3479
Mac Objective C Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

vijayakumar durai wrote:you can use
in scriptlet

out.println(request.getAttribute("String1");


Using Java code in JSP is a bad practice, no one encourages it.
 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

vijayakumar durai wrote:you can use wihtout scriptlet

"${param.String1}"



this will work only for parameters not attributes.
for attribute we can use attribute name directly ${String1}
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic