Hi,
I am updating a Java servlet to store cookies. The class inherits from HttpServlet and overrides the "service" method. Within this method I have the following code to test cookie storing and retreival:
public void service( HttpServletRequest req, HttpServletResponse res ) throws IOException
{
......
Cookie[] cookies = req.getCookies();
if( cookies != null )
{
for( int i = 0; i < cookies.length; i++ )
{
System.out.println(cookies[i].getName());
}
}
Cookie c = new Cookie("Acceptance","y");
res.addCookie( c );
But the cookies array I get back is always null. It never seems to store the "Acceptance" cookie. Can anybody help?
10 8610
The java servlet is being run from a UNIX platform. And I'm accessing the page that references the servlet from an NT machine. The page contains a link to a cgi-script and the cgi-script sends an HTTP request to the Java servlet.
Further, when I run getDomain() and getPath() on the cookie I create in the above code I just get null for the two. But using setDomain and setPath to correct this doesn't seem to help.
The java servlet is being run from a UNIX platform. And I'm accessing the page that references the servlet from an NT machine. The page contains a link to a cgi-script and the cgi-script sends an HTTP request to the Java servlet.
Further, when I run getDomain() and getPath() on the cookie I create in the above code I just get null for the two. But using setDomain and setPath to correct this doesn't seem to help.
I can't reaaly see what you are trying to do here. Have you read a tutorial on how to use cookies?
You are getting the cookie before you have created it!
No. I have done it that way so that first time round it won't find the cookie. However, when the method is entered the second time, shouldn't it find the cookie then? It doesn't seem to at the moment... And I've checked my "temporary internet files" folder to see if it's there, but it isn't.
Can't anybody help me? Why isn't it working?
I'm not going to relent. I really really really need help on this. Somebody must know!
I'm not going to relent. I really really really need help on this. Somebody must know!
gives you cookies sent from the clients. If you want this to contain anything, you set the cookies at the clients.
You are only sending a cookie from the server to the client in your code.
so request.getCookies() gets cookies from the client? Then how do I save cookies to the client if response.addCookie() saves it in the server. Can't I save cookies to the client from within the servlet. I would've hoped this would be possible as otherwise I can't see how useful the cookies API can be.
so request.getCookies() gets cookies from the client? Then how do I save cookies to the client if response.addCookie() saves it in the server. Can't I save cookies to the client from within the servlet. I would've hoped this would be possible as otherwise I can't see how useful the cookies API can be.
When you do
in a servlet, you include the cookie for the clients. When you get to the client you can get this cookie and use it. From the client, when you then send a request to the server, a new request is generated for each request. If you want the cookie to be available, get the cookie first in the client and send it to the server.
I cannot access client code. This all needs to be from within the servlet. Surely this must be possible.
Incidently after creating the cookie, when I do a getPath or a getDomain I just get null back. Is this expected?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Chris Morgan |
last post by:
I'm trying to get php to run on my webserver as a Java Servlet, it works the
first time but fails the second time and crashes the JVM with the following
error:
I have tried the latest versions...
|
by: Blossom |
last post by:
Hi there,
I have a problem with storing my Cookies. I made a servlet in which I
store a Cookie (in the doGet()-method) to detect whether a user has
already visited my webpage.
I used the...
|
by: ptaz |
last post by:
Hi I'm trying to run a web page but I get the following error. Ca
anyone please tell me a solution to this.
Thanks
Ptaz
HTTP Status 500 -
type Exception report
|
by: Mike |
last post by:
I have developed an application, for psyc patients.... they type in
very personal information in a web form to help them work through
problems in their lives. Once they enter the info, I encrypt...
|
by: TraceyAnnison |
last post by:
I wonder if you can help me - I'm new to this, and working in a project that has already been configured to work with Axis.
We have a Java project built with the Spring framework, in order to...
|
by: oll3i |
last post by:
when i run my jsp file i get an error
SEVERE: Servlet.service() for servlet jsp threw exception
java.util.MissingResourceException: Can't find bundle for base name MessagesBundle, locale pl_PL...
|
by: vijaykumardahiya |
last post by:
Hello Sir,
I have a simple Issue but It is not resolve by me i.e input parameter
are not store in Ms-Access.
I store the input parameter through Standard Action <jsp:useBean>.
jsp:useBean call a...
|
by: swethak |
last post by:
Hi,
i have a command to convert the video file into image
ffmpeg -i sample.wmv -f image2 -t 0.001 -ss 3 ss.jpg
i run that one in command prompt it converted the video file into...
|
by: ramprakashjava |
last post by:
This is index.jsp page code:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |