It's not a secret anymore!*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Problem regarding to Cookies with EL, HFSJ pg 386 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Problem regarding to Cookies with EL, HFSJ pg 386" Watch "Problem regarding to Cookies with EL, HFSJ pg 386" New topic
Author

Problem regarding to Cookies with EL, HFSJ pg 386

Mukunthan Shanmuganathan
Ranch Hand

Joined: Jul 24, 2007
Posts: 32
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>


Dare to know!
Tarun Yadav
Ranch Hand

Joined: Sep 20, 2007
Posts: 134
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

Joined: Jul 24, 2007
Posts: 32
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

Joined: Feb 05, 2003
Posts: 4727

There's a good chance you had cookies disabled in your browser!


A good workman is known by his tools.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Problem regarding to Cookies with EL, HFSJ pg 386