...

View Full Version : cookie from servlet does not get set



BubikolRamios
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"
"http://www.w3.org/TR/html4/loose.dtd">

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

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


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"));
}

}

BubikolRamios
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


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



in servlet


Cookie cookie = new Cookie("fromServlet","gfsdg");
cookie.setPath("/");
response.addCookie(cookie);



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum