View Full Version : cookie from servlet does not get set

12-13-2007, 09:15 PM
HTML - cookie generated there appears on client

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
response.addCookie(new Cookie("fromJsp","gfsdg"));

<jsp:include page="/mcLogin" flush = "true"/>

servlet - cookie generated here does not apear on client
the program gets here, I have a break point, no errors
???? what is that I dont see ?

package servlets;

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

public class mcLogin extends HttpServlet

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
response.addCookie(new Cookie("fromServlet","gfsdg"));


12-15-2007, 11:49 AM
narrowed down the problem:

1 and 2 works, 3 does not set cookie, although code in servlet gets executed, why ?

in jsp

<a href="http://localhost:8080/testWeb/mcLogin" >Set serverlet cookie </a>
<a href="/testWeb/mcLogin" >Set serverlet cookie2 </a>
<jsp:include page="/mcLogin" flush = "true"/>

in servlet

Cookie cookie = new Cookie("fromServlet","gfsdg");