• 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

Problem regarding to Cookies with EL, HFSJ pg 386

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Guys!

In order to check cookies with EL I code as follows,but I get "The User is:" and nothing else get printed.

Please kind enough to help me to get rid of this.

servlet.
-------

package com.foo;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class CookieTest extends HttpServlet {

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

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

response.setContentType("text/html");

PrintWriter out = response.getWriter();

String name = request.getParameter("name");

Cookie cookie = new Cookie("user",name);

response.addCookie(cookie);

RequestDispatcher view = request.getRequestDispatcher("result.jsp");

view.forward(request,response);

}

}

result.jsp
----------

<%@ page isELIgnored="false"%>
<html>
<body>
The User is: ${cookie.user.value}
</body>
</html>
 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Mukunthan Shanmuganathan:

String name = request.getParameter("name");



Are you sure you're getting a valid value here? Print it out and check...
 
Mukunthan Shanmuganathan
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Tarun Yadav,

Yes It does.

FYI:

Form.html
---------

<html>
<body>
<form method="POST" action="cookieset.do">
User Name: <input type="text" name="name">
<input type="submit">
</form>
</body>
</html>



:roll:
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's a good chance you had cookies disabled in your browser!
 
reply
    Bookmark Topic Watch Topic
  • New Topic