• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem regarding to Cookies with EL, HFSJ pg 386

 
Mukunthan Shanmuganathan
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • 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>
 
Tarun Yadav
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • 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
  • 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:
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's a good chance you had cookies disabled in your browser!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic