• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to Get a String attribute from Request Using EL?

 
Kathiresan Chinnasamy
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
 
Devi Taruni
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try this :

<cut value= "${pageContext.request.String1}"/>
 
vijayakumar durai
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
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65522
105
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.
 
Malatesh Karabisti
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: 65522
105
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.
 
Hussein Baghdadi
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.
 
Arvind Subramanian
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}
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!