This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

How to Get a String attribute from Request Using EL?  RSS feed

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • 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>
<cut value= "${String1}"/>
<cut value= "${requestScope.String1}"/>
<cut 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
  • Quote
  • Report post to moderator
try this :

<cut value= "${pageContext.request.String1}"/>
 
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
you can use wihtout scriptlet

"${param.String1}"
 
Kathiresan Chinnasamy
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you friends,

I got it
 
Author and ninkuma
Marshal
Posts: 66797
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
Java Oracle
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Posts: 66797
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
Bartender
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • 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
  • 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}
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!