Setting the cookies in jsp

Hi
Iam trying to add the cookie into local machine.Problems is i written cookie program in cookietest.jsp then i incude this jsp into index.jsp.When iam accessing the index.jsp cookies are not setting But when iam acessing cookietest.jsp cookies are adding.why index.jsp accessing time not adding??please help me how to achive this one.
below the code snippet
**********************cookietest.jsp***********************
<%@ page import="java.util.Date"%>
<%@ page import="java.net.*"%>
<%
     Date now = new Date();
     String timestamp = now.toString();
     Cookie cookie = new Cookie ("Venkateswarlu", "ravi");
     cookie.setMaxAge(365 * 24 * 60 * 60);
     response.addCookie(cookie);
%>
<HTML>
<HEAD>
</HEAD>
<BODY>
</BODY>
</HTML>
**************************end*****************************
***********************index.jsp***************************
<jsp:include page="/cookietest.jsp"/>
Thanks for advace
Venkatesearlu Ravi

Actually this is requirment
I have to add the that cookie code snippet to every
page.SO what i did is i placed the cookie code
snippet into footer.jsp.This footer jsp will include
every page..Here cookie is not adding.
Is there any solution.I also tried this with JSTL c:import, since the JSTL1.1 spec says that c:import covers many of the shortcomings of jsp:include.
/p/cookies/include.jsp
<%@ page import="java.util.Date"%>
<%@ page import="java.net.*"%>
<%
Date now = new Date();
String timestamp = now.toString();
Cookie cookie = new Cookie ("Venkateswarlu", "ravi");
cookie.setMaxAge(365 * 24 * 60 * 60);
response.addCookie(cookie);
%>
/p/cookies/page1.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:import url="/p/cookies/include.jsp"/>
<html>
<head><title>Page 1</title></head>
<body>
<%request.getCookies();%>
</body>
</html>
/p/cookies/page2.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:import url="/p/cookies/include.jsp"/>
<html>
<head><title>Page 2</title></head>
<body>
<%request.getCookies();%>
</body>
</html>
But the result is the same as jsp:include as far as setting HTTP Headers (Cookies) is concerned.
So the conclusion is that you can't really set HTTP headers in include files.
Then, you can try it with Servlets instead of JSPs. But then, you'll need to call the servlet each time, before every JSP is invoked.
I don' know how that's done. Probably through Filters
(a wild guess)
Message was edited by:
appy77

Similar Messages

  • Setting the cookies value

    hi,
    when i do, submiting the page i'm able to set the cookie value.I'm not getting any messages. But the Same time when i call the proceudre with parameters from the URL i'm not able to store the cookie value.
    It display's the message like this and the value is not stored in the cookies
    Content-type: text/html Set-Cookie: emp_no=9999X; path=/;
    my code is :
    owa_util.mime_header('text/html',FALSE);
         owa_cookie.send('emp_no',UPPER(lv_emp_no),null,'/',null,null);
    owa_util.http_header_close;
    How do i solve this problem?
    Thanks

    Hi,
    Here are a couple of things you can try:
    1) remove the following line because it shouldn't be necessary:
    the_cookie.num_vals :=0;2) remove the following line because the owa_cookie.send will automatically replace any existing cookie:
         owa_cookie.remove('emp_no',the_cookie.vals(1),null);3) try capturing the cookie value in a local variable and printing it (after htp.body, of course) to see if it is working correctly.
    4) enable the browser to prompt you when a cookie is being set so that you can verify whether it is being set or not.
    HTH,
    Ashesh Parekh
    Oracle9iAS Product Management
    hi,
    Something like this...
    Code
    PROCEDURE checkLogin ( emp_no in varchar2 default NULL) IS
         pv_check_f      BOOLEAN ;
    the_cookie      owa_cookie.cookie;
    BEGIN
    pv_check_f := FUN_EMP_PASSWORD(UPPER(emp_no) ) ;
    IF NOT pv_check_f THEN
         v_msg := 'Sorry Log on denied';
         RAISE EMP_ERROR;
         END IF ;
    the_cookie.num_vals :=0;
    the_cookie:= owa_cookie.get('emp_no');
    if the_cookie.num_vals= 0 then
              owa_util.mime_header('text/html',FALSE);
              owa_cookie.send('emp_no',UPPER(emp_no),null,'/',null,null);
              owa_util.http_header_close;
         else     
              owa_util.mime_header('text/html',FALSE);
         owa_cookie.remove('emp_no',the_cookie.vals(1),null);
              owa_cookie.send('emp_no',UPPER(emp_no),null,'/',null,null);
    owa_util.http_header_close;
    end if;
    htp.p('<script language="javascript">
    window.location="http://www...URL";
    </script>');
         htp.formclose;
    EXCEPTION
         WHEN EMP_ERROR THEN
         Pageheader;
    Procedurename.Banner('Login denied');
    htp.fontOpen('red','Arial Narrow');
    htp.header(3,lv_msg);
    loginagain;
    htp.fontClose;
    htp.centeropen;
         htp.br;
         htp.p('<INPUT type="button" value="Back" onClick="history.back()">');
         htp.br;
         htp.centerclose;
    pagefooter;
    END checkLogin;
    calling the Procedure "checklogin" with the parameter emp_no from the URL like this
    "http://....:8810/dir/Packname.checkLogin?emp_no=9ABCDS".
    Waiting for ur replay.
    Thanks.

  • How to set the cookie or session of one domain to another domain

    Hi,
    I am using tomcat server. I am facing a issue of session lost when I am moving from one domain to another domain.
    e.g. http://mydomain.com/ to http://a.mydomain.com.
    Is there any way to set the cookie or same session to sub domain in tomcat.
    Please help me. I will be highly obliged.

    a tutorial from JavaWorld
    http://www.javaworld.com/javaworld/jw-01-2001/jw-0126-servlets.html?page=1

  • Setting the cookies

    Hi
    I trying to add the cookie into local machines.Problems is i written cookie program on cookietest.jsp then i incude this jsp into index.jsp.When accessing the index.jsp the cookies are not setting But when iam acessing cookietest.jsp cookies are adding.why index.jsp accessing time not adding??please help me how to achive this one.
    below the code snippet
    **********************cookietest.jsp***********************
    <%@ page import="java.util.Date"%>
    <%@ page import="java.net.*"%>
    <%
         Date now = new Date();
         String timestamp = now.toString();
         Cookie cookie = new Cookie ("Venkateswarlu", "ravi");
         cookie.setMaxAge(365 * 24 * 60 * 60);
         response.addCookie(cookie);
    %>
    <HTML>
    <HEAD>
    </HEAD>
    <BODY>
    </BODY>
    </HTML>
    **************************end*****************************
    ***********************index.jsp***************************
    <jsp:include page="/cookietest.jsp"/>
    Thanks for advace
    Venkatesearlu Ravi

    <jsp:include page="/cookietest.jsp"/>Since you are using <jsp:include> it is only going to include the response from the cookietest.jsp. The cookie setting part gets lost in between the page include. Use the include directive instead.
    <%@ include file="relativeURL" %>The include directive includes the code at jsp compile time and the cookie setting code will get processed when it really should.

  • Setting the sessiontime in jsp on oracle9i AS

    hello friends..
    i m getting a problemm in jsp page..
    while working on oracle 9iAs i m unable to set the seesion time ..
    coz jsdk version is not suppoting this..
    is there any other method to configure the session time..
    plz let me know asap..
    bye..
    plz mail me at [email protected]

    Are you refering to HttpSession cancellation through a timeout
    check out the doc at
    http://otn.oracle.com/docs/products/ias/doc_library/90200doc_otn/web.902/a95878/developi.htm#999707
    -Prasad

  • How to set the default login jsp page?

    i have written a jsp page called Login.jsp. i want it to be the default jsp page when i type the url "http://localhost:8080" , instead of the index.html of tomcat . how to make it ?

    It's in web.xml, eg. :
    <web-app>
      <welcome-file-list>
        <welcome-file>Login.jsp</welcome-file>
      </welcome-file-list>
    </web-app>

  • How to set the domain of a cookie in localhost environment

    in some scenario i have to set the domain of cookie on my local environment,
    how can be done?????????????
    i.e http://localhost:7001/myapp/testservlet
    how to set the cookie domain for "myapp"

    Hi
    After Some googling I could find out this for you. I think it is a bug with IE.
    http://www.webmasterworld.com/forum21/11530.htm
    The idea is to use a virutal host.
    HTH
    VJ

  • How can we access the cookie set by cfheader in the same request?

    I've set a cookie in my application.cfm using cfheader and in the same request i need to access the cookie. How can i do this?

    Unless you know the values you're setting in the cookie explicitly then I don't know if you can - not sure if it's one of those things whereby a cookie doesn't exist until it's hit their browser, and if you page hasn't finished rendering then it hasn't hit their browser.
    I'd suspect you'll try it and either it'll work or it won't.
    If you're setting the cookie explicitly with you own UUID's or similar you will of course know what you'll be setting it to.
    If that made any sense.
    Which I'm pretty sure it didn't.
    O.

  • Can we change the name of the cookie - JSESSIONID?

    Can we change the name of the cookie- JSESSIONID?
    for eg.
    Set-Cookie = [ JSESSIONID=6ad8360e0d1af303293f26d98e2a; Version=1; Comment=Sun+ONE+Application+Server+Session+Tracking+Cookie; Path=/]
    can we change it to something like -
    Set-Cookie = [ ServletSession=RkA4OlbgfW; path=/]

    Thankyou Sultal for the response.
    Actually we are migrating the application server from Weblogic5.1 to Sun application server 8.2. The client is a mobile client and it sends the Cookie as 'JSESSIONID=session_id_val&WeblogicSession=session_id_val' as parameters, not as request header.It worked fine for Weblogic5.1 but not in Sun Application Server.
    To make it clear :
    Weblogic           :     request.getsession(false) = sessionObj@value
    Sun Application Server      :     request.getsession(false) = null
    Sun Application Server      :     request.getParameter("JSESSIONID") = session_id_val
    In the Weblogic5.1 we have set the cookie & session parameters in the weblogic.properties file as:
    weblogic.httpd.session.cookies.enable=true
    weblogic.httpd.session.cookie.name=WebLogicSession
    weblogic.httpd.session.neverReadPostData=false
    weblogic.httpd.session.timeoutSecs=120
    In case of Sun application server , JSESSIONID is not coming as a cookie , request.getsession(false) is returning null value.Is there a way to initialize the session with JSESSIONID request parameter?

  • Firefox wrecked the cookie functions in Safari

    I'm reporting a bug that started after setting the cookies option in Firefox to "block all". There was no real reason to do this I was just testing the new toolbar gizmo I'd gotten from somewhere. I turned it back on but then...
    Now neither Safari or Firefox can access my Amazon.com cart or perform cookie based security at my email provider.
    I've tried deleting the plist files for both and rebooting and ...
    Any ideas?
    Regards,
    Dave

    There was no real reason to do this
    Then why did you do it?
    I was just testing the new toolbar gizmo I'd gotten from somewhere.
    What is the exact name of this "toolbar gizmo" and what is it supposed to do?
    Now neither Safari or Firefox can access my Amazon.com cart or perform cookie based security at my email provider.
    That's not any indication of a bug.
    I've tried deleting the plist files for both and rebooting and ...
    Doing that was a waste of time, since it would have no effect on any cookies.
    We need a lot more details if you want help for this problem. But until there is firm, reproducible evidence of a bug in Safari or Firefox, you should stop making that assumption.
    Mulder

  • I successfully add a cookie, but cannot read the cookie in another jsp page

    Putting cookie*******************************
    page1.jsp
    <%Cookie adam = new Cookie("adam", "adam");
    adam.setMaxAge(3600*365);
    response.addCookie(adam);
    %>
    Reading cookie*********************************
    page2.jsp
    <%String userid = "";
    Cookie[] cookies = request.getCookies();%>
    <%=cookies.length%>
    <%for (int i = 0; i < cookies.length; i++) {
    Cookie aCookie = cookies;
    if (aCookie.getName().equals("adam")==true){
    userid = aCookie.getValue();%>
    <%=userid%>
    <%break;
    }%>
    I checked my cookies and it did drop the cookie.
    cookies.length = 1
    Cookie[0] contains garbage or encrypted data.
    Does anyone know what I am doing wrong

    Hi, are you sure that is not a problem of paths,
    in you page where you get the cookies try
    cookie.getPath() to see from where are you trying to get it, could be different from the path where you set it.
    The documentation of the Cookie class
    (http://java.sun.com/products/servlet/2.2/javadoc/index.html) can help you more.
    I am sure that this is the problem.
    Regards,
    Ionel C.

  • JSP, Data Web Bean, BC4J: Setting the where clause of a View Object at run time

    Hi,
    I am trying to develop a data web bean in which the where clause of a View Object will be set at run time and the results of the query then displayed.
    My BC4J components are located in one project while the coding for the data web bean is in another project. I used the following code bu t it does not work. Could you please let me know what I am doing wrong?
    public void populateOSTable(int P_EmpId)
    String m_whereString = "EmpView.EMP_ID = " + P_EmpId;
    String m_OrderBy = "EmpView.EMP_NAME";
    oracle.jbo.ApplicationModule appModule = null;
    ViewObject vo = appModule.findApplicationModule("EMPBC.EMPAppModule").findViewObject("EMPBC.EMPView");
    vo.setWhereClause(m_whereString);
    vo.setOrderByClause(m_OrderBy);
    vo.executeQuery();
    vo.next();
    String empName numAttrs = vo.getAttribute(EmpName);
    System.out.println(empName);
    Thanks.

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by JDev Team (Laura):
    Here is how I have usually done mine:
    1. In the JSP, use a RowsetNavigator bean to set the where clause and execute the query.
    2. Use a custom web bean to process the results of the query (print to HTML).
    for example:
    <jsp:useBean class="oracle.jbo.html.databeans.RowsetNavigator" id="rsn" scope="request" >
    <%
    // get the parameter from the find form
    String p = request.getParameter("p");
    String s = request.getParameter("s");
    // store the information for reference later
    session.putValue("p", p);
    session.putValue("s", s);
    // initialize the app module and view object
    rsn.initialize(application,session, request,response,out,"wt_bc_WT_bcModule.wtjoinView");
    // set the where clause string
    String theclause = "presname = '" + p + "' AND slideno=" + s;
    // set the where clause for the VO
    rsn.getRowSet().getViewObject().setWhereClause(theclause);
    rsn.getRowSet().getViewObject().executeQuery();
    rsn.getRowSet().first();
    %>
    </jsp:useBean>
    <jsp:useBean class="wt_bc.walkthruBean" id="wtb" scope="request" >
    <%
    // initialize the app module and VO
    wtb.initialize(application,session, request,response,out,"wt_bc_WT_bcModule.wtjoinView");
    wtb.render();
    %>
    In this case, the render method of my custom web bean mostly gets some session variables, and prints various content depending on the session variable values.
    Hope this helps.
    </jsp:useBean><HR></BLOCKQUOTE>
    Laura can you give the code of your walkthru bean? i wna't to initialize a viewobject, set the where clause and give that viewobject back to initialize my navigatorbar.
    Nathalie
    null

  • Where is the cookie manager on Firefox. Can I set Firefox to ask me first to allow individual cookies?

    I read the follow article.
    http://www.mozilla.org/projects/security/pki/psm/help_21/using_priv_help.html
    In this article under "Managing Cookies Site-By-Site" It said
    "To control cookies on a site-by-site basis:
    1. Open the Tasks menu, choose Privacy & Security, and then choose Cookie Manager.
    2. Choose "Unblock Cookies from this Site" or "Block Cookies from this Site."
    When you are warned (while browsing) that a web site is requesting to set a cookie, you can click Yes to allow or No to deny the cookie. You can also select the option for your browser to "Remember this decision."....
    My questions is 1. I can't find the cookie Manager in firefox (I have the latest version). The article said "Open task menu, choose Privacy&Security... is that they same as under menu bar, tools, options, privacy (but under this option I don't see the cookie manager mention in the article. (I am thinking what they are describing is not for the version of firefox I have?).
    Bottom lines, I want to set Firefox so It will ask me each time the website want to install a cookie and for me to decide to allow that or not. I article above seem to describe how to do that but either I am looking in the wrong place or I am not doing it right.
    thanks in advance.
    panzer_ace

    Hi,
    I think that what you are searching be in Tools >> Options >> Privacy >> On Firefox will: change to "Use custom settings for history" then Button Show Cookies will be allowed and you will see the cookies in your browser in the next window
    If you uncheck "Accept cookies from sites", probably the sites that need cookies will alert you that you need active the storage cookies

  • HOW to set the value attribute of FORM INPUT data to a variable in a JSP

    eg. Registration.jsp
    The data is accessed from an hidden field called course
    for example, if I have "Java programming" in the field course, and I use
    an expression to access the value from the hidden field.
    **My problem is that the data gets truncated to "Java" , I need "Java Programming"to display. The code looks like this
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <INPUT TYPE="text" SIZE=12 NAME="course"
    VALUE=<%=getParameter("course") %>
    IS there ANY OTHER WAY to set the value of VALUE to a variable?

    Instead of value=<%=request.getParameter("course")%>
    Use double codes
    value="<%=request.getParameter("course")%>"

  • HT1677 In safari browser cookies is working fine. But when I add the browser url to the screen then the cookies concept is not working. In safari setting cookies is always open only. Can you please provide any information regarding to this?

    In safari browser cookies is working fine. But when I add the browser url to the screen then the cookies concept is not working. In safari setting cookies is always open only. Can you please provide any information regarding to this?

    Hello,
    '''Try Firefox Safe Mode''' to see if the problem goes away. [[Troubleshoot Firefox issues using Safe Mode|Firefox Safe Mode]] is a troubleshooting mode that turns off some settings and disables most add-ons (extensions and themes).
    ''(If you're using an added theme, switch to the Default theme.)''
    If Firefox is open, you can restart in Firefox Safe Mode from the Help menu by clicking on the '''Restart with Add-ons Disabled...''' menu item:<br>
    [[Image:FirefoxSafeMode|width=520]]<br><br>
    If Firefox is not running, you can start Firefox in Safe Mode as follows:
    * On Windows: Hold the '''Shift''' key when you open the Firefox desktop or Start menu shortcut.
    * On Mac: Hold the '''option''' key while starting Firefox.
    * On Linux: Quit Firefox, go to your Terminal and run ''firefox -safe-mode'' <br>(you may need to specify the Firefox installation path e.g. /usr/lib/firefox)
    ''Once you get the pop-up, just select "'Start in Safe Mode"''
    [[Image:Safe Mode Fx 15 - Win]]
    '''''If the issue is not present in Firefox Safe Mode''''', your problem is probably caused by an extension, and you need to figure out which one. Please follow the [[Troubleshoot extensions, themes and hardware acceleration issues to solve common Firefox problems]] article to find the cause.
    ''To exit Firefox Safe Mode, just close Firefox and wait a few seconds before opening Firefox for normal use again.''
    When you figure out what's causing your issues, please let us know. It might help others with the same problem.
    Thank you.

Maybe you are looking for

  • Error running a query

    Hi, When i try to run a query i get to a point it asks me to input the values. Once i do that i get an error ther is an UNCAUGHT_EXCEPTION in class SAPMSSY1 method. As a result the system has been disconnected from BI server. I went through  Note 931

  • Using non-US credit card in US iTunes Store

    I've registered my account on US iTunes store with my US credit card. I'm not living in the States anymore, i'm living in Turkey. I wonder if I change my credit card details with the new Turkish credit card, would my account set to iTunes Turkey? Bec

  • Run Apple Script in User Space

    Hi, My application runs in administrator privileges . I want to run an apple script from the application in user space . Please guide me . Thanks

  • IPhoto is driving me mad

    I've been driven insane by iPhoto I've an old imac G3 upgraded to OS 10.3.9 It's beginning to die (topic in another forum!) and I'm trying to back up the 900+ photos of my children onto an external DVD drive. The problem is that evry time I've downlo

  • Global button problem

    Hi, I have created a function companyname_help of type jsp with some x.jsp .I have used .In my page controller i have written fllwoing code. XClassFile obj=new X classfile(); obj.setHelpGloablbutton(pageContext); <BR><BR><BR> in class file which exte