Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,963
    Thanks
    120
    Thanked 76 Times in 76 Posts

    cookie from servlet does not get set

    HTML - cookie generated there appears on client
    Code:
    <%@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 ?

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

  • #2
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,963
    Thanks
    120
    Thanked 76 Times in 76 Posts
    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);


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •