Session timing in jsp/servlets

Hi all..!
I have a small problem..Plz help me..
We are developing an application in JSP, Servlets on Linux Platform. Here, the default session time set is 30 mins. But I need to extend it by another 15 mins.. i.e., my session should be set to atleast 45 mins..
I can do it using the setMaxInactiveInterval(int interval). which sets the amount of time that the session will remain active between requests
before expiring and the int getMaxInactiveInterval() , Which will return the length of time that the session will remain active between requests before
expiring.
Through the above method,I can set the session time. But the version of Servlets I have on my system is 2.0 JAR. and The above mentioned methods work only for servlets version 2.1 and above..
Could U plz suggest a way where I can set the session time for the version of servlets I have?? Plz help me with the solution in servlet/jsp.
This is quite urgent. Plz try and help me.
Thanx and regards
Aparna

Hi Aparna,
It seems that u can't set and get the Session timing in servlet 2.0, because the setMaxInactiveInterval() and getMaxInactiveInterval() methods are being introduced only in 2.1.
But One thing u can try out. Use getLastAccessedTime() method, which will return the last time that a client sent a request for that session. After that u can easily calculate the inactive time. Hope it will work.
ragards,
Atanu
Hi all..!
I have a small problem..Plz help me..
We are developing an application in JSP, Servlets on
Linux Platform. Here, the default session time set is
30 mins. But I need to extend it by another 15 mins..
i.e., my session should be set to atleast 45 mins..
I can do it using the setMaxInactiveInterval(int
interval). which sets the amount of time that the
session will remain active between requests
before expiring and the int getMaxInactiveInterval()
, Which will return the length of time that the
session will remain active between requests before
expiring.
Through the above method,I can set the session time.
But the version of Servlets I have on my system is 2.0
JAR. and The above mentioned methods work only for
servlets version 2.1 and above..
Could U plz suggest a way where I can set the session
time for the version of servlets I have?? Plz help me
with the solution in servlet/jsp.
This is quite urgent. Plz try and help me.
Thanx and regards
Aparna

Similar Messages

  • Session Maintenance in JSp-- Servlet-- JSP

    Iam making a browser based Financial Aplication so I want to introduce sessions into it.
    My First page is a JSP which takes username and Password. Then it calls a servlet.
    So my Problems are-
    1. Iam able to start session from servlet (which validates username and password) but after that in the apllication some JSp's are there like for search options so how to maintain sessions in JSP's ?
    2. When user quits browser and then opening a browser and directly types a JSP page which is in-between the flow this JSP opens up whereas i want the user to go from starting as its a security loop hole.
    So how to maintain a session in a JSP (ie when control passes from Servlet to JSP at that time)?
    Plz Help me
    Thanks in advance

    Hi Innova,
    There is a solution .I think while validating the login page entries u should maintain a session variable and give it some constant value if the entered values are valid.And now u should always check this sesson variable for that constant value [ if(session.getParameter("s")==constvalue) ] only then u proceed further else diaplay an error message or link prompting to login
    I hope it will work fine check it out.
    GoodLuck.
    Bye......

  • How to use session variable in JSP function  & How to use both JSP  Servlet

    Hi,
    I am new to JSP and servlets
    Still I am devloping a website in JSP. I am not mixing JSP with servlets, but I do create Java files for bean, logic and database works.
    I try to keep the hard coding part out of JSP.
    I dont how to use both JSP and Servlets in combination.
    Hence If needed I write some functions in JSP.
    but it gives me error
    +<%! public void abc()+
    +{+
    int intUserId = Integer.valueOf((Integer) session.getAttribute("MySession_UserID"));
    +}+
    +%>+
    Saying cannot find symbol session
    1) So can u please tell how can I access session variables within JSP function
    2) And also give me some links/tutorials about useing both JSP and Servlets in combination.
    Thanks
    Venkat

    The application architecture when you use Servlets and JSP in a standard MVC pattern is explained here (under the heading "Integrating Servlets and JSP Pages") and here ...

  • Passing session data between jsp and servlet

    I have a servlet that I pass data to my jsp.
    I do a session.setAtrribute in the servlet. No problem.
    I get the data no problem in the jsp that I call.
    How do I pass this same data to the another servlet?
    I basically have an array of values that I already have in the existing jsp that has been set in session.
    When I call the secondary servlet, I don't have anything in this session variable related to my array.
    Prior to posting to my next servlet, do I need to do another setAttribute inside the jsp to get the data passed to the servlet?
    Thanks.

    Two different things. The encoding adds this to the URL (after the page, before the query string
    ;jsessionid=ABC123 but only if the user isn't using cookies.
    So in your example, you would do this (maybe):
    <%
      String url = response.encodeURL("Servlet");
    %>
      <form name="form1" method="post" action="<%= url %>?cmd=pay"> ... Or some modification.
    So the difference between encodeing and using a post is that
    1) encoding adds the jsessionid to the url string if necessary. It does nothing else
    2) POSTing will send a request to the provided URL via the POST method, including the inputs of the form as parameters to the URL.
    They really don't interact with each other. It is like asking what is the difference between the Color Orange and thr Size Big? They can both be applied to the same thing, or not... and have no real relation to each other.

  • How to create session in JSP & Servlet

    Hi All
    I'm really new to JSP & Servlet. So I want to know how to create sessions and how to pass details to another web page
    Thanks
    Padma

    You can easily pass objects from one jsp or servlet to another.
    On your servlet execute method (for example), you can do this as follows:
    HttpSession session = request.getSession();
    User u = new User();
    session.setAttribute("user", u);And get it again on other servlets:
    HttpSession session = request.getSession();
    User user = (User) session.getAttribute("user");I hope this helps you.

  • Retrieving session data in JSP  which is forwarded from a servlet

    I'm trying to retrieve session data which is set in a servlet and pass to a jsp. But its returning NULL . The session IDs are equal.
    Scenario:
    JSP display the checkbox, user selects it and submits to a servlet. the servlet display the selected items and stores the data in session.
    when the user press back button in servlet all i want to do is display those checked box which were selected before as checked in the JSP so that user can edit.
    Following is a small test code
    JSP
    <html>
         <head>
              <title>Item List</title>
         </head>
         <body bgcolor="#fedeab"><br><br><br>
         <p align=center>
              <font size=4>
              Choose the item you want!!!
         </p>
         <form action="/demo/showitem" method="post">
              <%=session.getId()%>
              <div align=center>
              <fieldset style="width:250px">
              <legend style="text-align:center">List of item</legend> <br>
              <%     
                   if (session.getAttribute("book1")!=null) {
              %>
                   <input type="checkbox" name="book1" value="book1" checked > Book 1 <br>
              <% } else {%>
                   <input type="checkbox" name="book1" value="book1" > Book 1 <br>
              <% }%>
              <input type="submit" value="Enter">
              </fieldset>
              </div>
         </form>
         </body>
    </html>               
    Servlet
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class ShowItem extends HttpServlet
         public void doPost (HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException
              HttpSession session = req.getSession(true);
              res.setContentType("text/html");
              PrintWriter out = res.getWriter();
              out.println(session.getId());
              out.println("<br>");
              out.println("<form>");
              String book1 = req.getParameter("book1");
              session.setAttribute("book1",book1);
              if (book1 != null)
                   out.println ("1." + book1 +"<br>");
                   out.println("<br><br><input type=\"submit\" name=\"buy\" value=\"Buy\">");
              else
                   out.println("No item to display<br>");
              out.println("&nbsp&nbsp<input type=\"submit\" name=\"back\" value=\"Back\">");
              out.println("</form>");
              RequestDispatcher page = getServletContext().getRequestDispatcher("/jsp/litemlist.jsp");
              if ((req.getParameter("buy"))!= null)
                        page.forward(req, res);
              if ((req.getParameter("back"))!= null)
                        page.forward(req, res);
         public void doGet (HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException
              doPost(req,res);
    }

    req.getParameter("book1") is not NULL and returning the value of the checkbox "book1". The problem occurs when the back button is press and try to retrieve the session value in the JSP. At that time, session.getAttribute("book1") returns NULL.
    But if i convert the servlet to JSP then everything is working fine.
    So i wanted to know if there is anything wrong in the way i store the session value in the servlet and forwarding to the JSP.
    Thanks

  • How to track the same session using both jsp and servlets

    Hello, guys:
    "how to use jsp and servlet to track the same session",
    it seems to me my logoff.jsp never realize the session I established in my servlets.
    Here is how I set my session in my servlets:
    "     HttpSession session = req.getSession(true);
    session.setAttribute("userid",suserid);"
    Here is how I invalidate my session in my logoff.jsp
    " <%@ page language= "java" %>
    <%@ page import="javax.servlet.http.HttpSession" %>
    <%@ page session="false"%>
    Our Session id is : <%= session.getId() %>
    <% session.removeAttribute("userid");
    session.invalidate();
    %>
    Our Session id is : <%= session.getId() %>"
    but when I try to logoff using the logoff.jsp
    I always get following error message.
    "/home/jiao/jsp_webserver/tomcat/work/Standalone/localhost/syllabus/htmls/logoff_jsp.java:50: cannot resolve symbol
    symbol : variable session
    location: class org.apache.jsp.logoff_jsp
    out.print( session.getId() );"
    T.I.A.
    [Edited by: jiveadmin on Jun 18, 2003 10:32 AM]
    [Edited by: jiveadmin on Jun 18, 2003 10:33 AM]

    So,
    <%@ page session="false"%>
    That means the jsp never instantiates the build in session object.
    <%@ page session="true"%>
    means jsp will instantiates a session object if there are no existing ones
    how about I just delete the line,
    does that mean the jsp will find the existing session object for me?
    So I can do something like
    Our Session id is : <%= session.getId() %>
    <% session.removeAttribute("userid");
    session.invalidate();
    %>
    directly.
    T.I.A.

  • How to know if a session finished in jsp

    Hello,
    How to know if a session finished in jsp?
    Help me please.
    Best Regards.
    Joseph

    Depends. You can create a javax.servlet.http.HttpSessionListener implementation and register it in the web.xml file (I forget the syntax, though), which can notify you of sessions being created and destroyed.
    Or you can create a javax.servlet.http.HttpSessionBindingListener implementation and add it to the session (setAttribute()) and it'll have it's valueUnbound method called when the session expires (or the attribute is removed, but if you don't remove it, the session invalidating will). That's a good place for session-specific clean-up.

  • Jsp / Servlet / bean / upload

    Hello,
    I use a jsp to enter several fields. These fields are sent to a servlet by using a bean (recorded in the current session). Until now there is no problem. The servlet receives all information. Now I must also send 5 files which must be stored on the server. I have thus to add in my jsp 5 file fields.
    My question :
    Is it possible to integrate the FileUpload package for uploader my files without anything to change in my code (by using of a bean to exchange the data between my jsp and my servlet). ??
    In other words, it is possible to use my bean to also transport files. ??
    Tank u for u help

    Yes it is possible..
    download cos.jar from www.oreily.com for file upload..
    it will read dat from the form as two parts ..
    parameter part and file part..
    and you can implement it throgh a servlet easily..
    for more follow oreily JSP/servlets Cookbook

  • Jsp,servlet,bean question,please help

    The Tomcat Web server set up like this.......
    The directory structure is
    e:/sampleapp/WEB-INF/classes
    /lib
    And the web.xml is in the WEB-INF for the use of ay potential servlet.
    The basic understanding is that all the .java files go into the WEB-INF directory and the .class files go into the classes directory.
    All the .jsp files go into the sampleapp directory.Till here is correct I feel.
    Now for my qustion......
    I plan to use jsp,servlet and beans for a potential web application...,where do all these files go?,just the same as above or is there a difference.
    Hope that I have given a reasonable explaination to my question.
    Thanks for any replies
    AS

    All of your compiled servlet and java bean (java
    classes in general) will be placed into the following
    directory (under a directory structure matching the
    java package they are in):
    e:/sampleapp/WEB-INF/classesAll of your .jar files that are used as libraries (not
    your .jar files for applets):
    e:/sampleapp/WEB-INF/libAll of the rest of your JSP files, javascript files,
    HTML files, JAR files, images files, etc. will go into
    the following directory:
    e:/sampleappYou must make sure you put your sampleapp directory
    where tomcat can load it. Or use the admin tool to
    load it. If you make a .WAR file with a corresponding
    web.xml file in it, it will simplify loading it into
    tomcat. It also will help you do your servlet
    mappings, etc. I hope this helps.Thanks for your timely response.To add to it,let me tell you.
    The <b>bean</b> files are put into a package right,so they should be put into the WEB-INF/classes/<package name>
    What about The <b> servlet </b> files...... they are just put into the WEB-INF/classes/ directory????
    Kindly let me know.
    Thanks
    AS

  • How the hell does a person share session data between JSP page and a Servle

    1. How the hell does one share session data between a servlet and a JSP page without using a bean but rather using a normal string variable.
    2. When using session scope to access a bean the application complains about not finding the bean on the specified scope, however when I use an application scope the save the same bean, the application does find it.
    Please help!!!!!!!
    SERVLET:
    HttpSession session = request.getSession(true);
    ServletContext servletContext = session.getServletContext();
    customerID = result.getString("CustomerID");
    userName = result.getString("UserName");
    session.setAttribute("UserName",userName);
    session.setAttribute("CustomerID",customerID);
    System.out.println("Customer UserName = " + session.getAttribute("UserName"));
    response.sendRedirect("/economics/subscriptions/default.jsp");
    JSP PAGE:
    <?xml version="1.0" encoding="UTF-8"?>
    <jsp:root xmlns:jsp=http://java.sun.com/JSP/Page mlns:c="http://java.sun.com/jsp/jstl/core" xmlns:sql="http://java.sun.com/jsp/jstl/sql" version="2.0">
    <jsp:directive.page isThreadSafe="true" session="true" contentType="text/xml"/><jsp:output omit-xml-declaration="false"/><jsp:scriptlet>response.addHeader("x-xslt-nocache", "true");</jsp:scriptlet><pml>
    <page type="web" search="y">
         <pageName>Commercial Banking</pageName>
         <jsp:directive.include file="/economics/header.inc"/>
         <jsp:directive.include file="/login.inc"/>
         <jsp:directive.include file="/economics/leftMenu.inc"/>
         <!--<jsp:useBean id="UserName" type="java.lang.String" scope="session" />-->
         <content>
         <searchSum>Commercial - Main Content</searchSum>
         Value = <c:out value="${request.session.getAttribute("UserName")}"/>
         </content>
         <jsp:directive.include file="/economics/rightNav.inc"/>
         <jsp:directive.include file="/footer.inc"/>
    </page></pml></jsp:root>

    For a start, just "session" instead of "request.session" would work better. But why did you post this here and not in the JSP forum? Doesn't seem to have anything to do with Java programming.

  • Showing session data on new servlet

    I am writing a java servlet and trying to bring session information to another servlet screen in order to edit the data. When I bring up the fields on the screen the session data does not show. Here is a copy of the java program.
    public void doPost( HttpServletRequest req,
    HttpServletResponse res)
    throws ServletException, IOException
    res.setContentType("text/html");
    PrintWriter out = res.getWriter();
    HttpSession session = req.getSession(true);
    if(session == null)
    System.out.println(" No record found.");
    else
    String memberID = (String)session.getAttribute("memberID");
    System.out.println("Record found in modify. " + memberID);
    out.println("<jsp:useBean ID=\"memberID\" CLASS=\"Member\"/>");
    out.println("<jsp:SetProperty NAME=\"setMemberID\"PROPERTY=\"memberID\" />");
    out.println("<html>");
    out.println("<head>");
    out.println("<title>Member Modify</title>");
    out.println("</head>");
    out.println("<body ONLOAD=\"dynAnimation()\">");
    out.println("<p ALIGN=\"center\" STYLE=\"border: 4px ridge #FFFF00; \">");
    out.println("<font SIZE=\"5\" FACE=\"BookmanITC Lt BT\">MEMBER MODIFY</font></p>");
    out.println("<form METHOD=\"POST\" ACTION=\"http://localhost:8080/servlet/PetShop.membermodify\" " +
    "ONSUBMIT=\"location.href='_derived/nortbots.htm';return false;\" NAME=\"FrontPage_Form1\" " +
    "WEBBOT-onSubmit=\"return FrontPage_Form1_Validator(this)\">");
    out.println(" <p ALIGN=\"center\"> </p>");
    out.println(" <p> </p>");
    out.println(" <p ALIGN=\"left\"> " +
    " & nbsp; Member ID: " +
    " <input TYPE=\"text\" NAME=\"memberID\" value='<%=req.getParameter (\"setMemberID\")%>'" +
    "SIZE=\"20\" MAXLENGTH=\"20\" TABINDEX=\"1\" />");
    I've also tried:
    value="<%=setMemberID%>"
    But I either get no data or the expression I put in. I also did a system.out.println to see if the session data is there and it is.

    String memberID =
    (String)session.getAttribute("memberID");
    System.out.println("Record found in modify. " +
    memberID);
    value='<%=req.getParameter (\"setMemberID\")%>'"
    I've also tried:
    value="<%=setMemberID%>"
    But I either get no data or the expression I put in.try memberID instead of setMemberID
    (as in value="<%= memberID %>" or request.getParameter("memberID") )

  • Help!! unable to set the session timing

    Hello Friends...
    while working with oracle9i Application server ..
    when throught JSP i m setting the time for a session with the help of setMaxInactiveInterval(int);
    of seesion object ..
    it is not supporting this method may be due to some older version..
    is there any other method to set thje session timing..
    plz let me know asap..
    thanks
    mich

    Hello,
    Please avoid any personal information within these forums...they are public, and you have just posted your personal email address for all spammers to troll for and use. Not wise.
    Rather, you need to contact your carrier. To use the proprietary RIM Push email capability, you must have an adequate data plan from your carrier. The carriers host BIS for their BB users. Typically, BIS is not available via generic data plans. Many carriers call what is necessary The Blackberry Data Plan. Whatever they call it, it is the carrier who delivers BIS to their BB users -- contact them for assistance. Once you have a BIS-capable data plan on your BB (at whatever fees your carrier will charge, btw), you will then have Personal Email added to the email setup wizard.
    Good luck!
    Occam's Razor nearly always applies when troubleshooting technology issues!
    If anyone has been helpful to you, please show your appreciation by clicking the button inside of their post. Please click here and read, along with the threads to which it links, for helpful information to guide you as you proceed. I always recommend that you treat your BlackBerry like any other computing device, including using a regular backup schedule...click here for an article with instructions.
    Join our BBM Channels
    BSCF General Channel
    PIN: C0001B7B4   Display/Scan Bar Code
    Knowledge Base Updates
    PIN: C0005A9AA   Display/Scan Bar Code

  • JSP / Servlet / OAS 4.0.8.2

    I try to create a session thru JSP, and try to get that session thru servlet. However,
    the servlet can't get the session. How can I make the JSP and servlet communicate thru session under Oracle Application Server 4.0.8.2. ( Note : the JSP and sevlet is under the same application but in different cartridges )
    My JSP code :
    <%@ page session= "true" %>
    <%session.putValue( "name", "brian" ) ; %>
    My Servlet code :
    HttpSession lSession = request.getSession( false ) ;
    null

    Hi Brian,
    Direct from the release notes for OJSP 1.0.0.6.1:
    (new features)
    - New configuration parameter: session_sharing; default value = true;
    Function: This flag relates to session data sharing between JSPs & servlets.
    Previously, when a JSP put a value into the session object, servlets in
    the same JVM could not see the value (directly). It is because the session
    in Oracle JSP is a session wrapper object, and not the original session object
    provided by the servlet container. The values stored in the Oracle
    JSP session were not exposed to the underlying servlet session directly.
    This flag allows easier use of the original session object. The session
    object in Oracle JSP is now the actual servlet session object, if there is
    no globals.jsa file present for the application. For those who are using
    globals.jsa (a beta feature), the JSP session wrapper now by default will
    share the session data with the underlying servlet session object.
    This behavior could be changed by setting initArgs: session_sharing=false.

  • Menu item in Jsp/Servlet

    Hi experts, when you're using Jsp/Servlet to implement the front-end web application, what options do you have for implementing some menu dropdown?
    Is awt or swing can be used for that purpose?
    How would you go about the layout management issue?
    Thanks, and your reponse is appreciated

    I guess You are looking for a solution in JSP/Servlets. Here is my program that might be help ful to you. This program will bring a drop down list that fetches the values from the database.
    <table cellpadding=4 cellspacing=2 border=0 align=center>
    <TR>
    <TD><B>choose Code</B></TD>
    <TD valign=top>
    <!-- this code is to generate the list of Codes-->
    <% String userId =(String) session.getValue("userName"); %>
    <%
    Connection con = null;
    Statement stmt = null;
    ResultSet rs = null;
    String uId;
    String returnString="";
    String null_value="";
    try {
    Class.forName("oracle.jdbc.driver.OracleDriver");
    con = DriverManager.getConnection("jdbc:oracle:thin:@serverName:1521:localHost", "scott", "tiger");
    if (con == null) {
    System.out.println("Connection not found");
    stmt = con.createStatement();
    con.setAutoCommit(false);
    String sql= "select code from example_list where user_id='"+userId+"'";
    rs= stmt.executeQuery(sql);
    %>
    <select name="alcList">
    <%String aString;
    rs= stmt.executeQuery(sql);
    while (rs.next()) {
    %>
    <option value="<%= aString = rs.getString("code") %>">
    <%= aString %></option> <%}%></select><%
    con.commit();
    //returnString= true;
    } catch(SQLException sqlex) {
    sqlex.printStackTrace();
    //return returnString;
    } catch(Exception ex) {
    ex.printStackTrace();
    } finally {
    stmt.close();
    con.close();
    stmt = null;
    rs = null;
    con = null;
    %></TD>
    <TD align=center>
    <INPUT TYPE=submit SIZE=30 VALUE="Submit"></TD>
    </TR>
    </Table>
    </FORM>
    </BODY>
    </HTML>if this doesn't answer your problem, Please post your question exactly. May be I can help you out.
    Good Luck.
    -Sreekanth varidhireddy

Maybe you are looking for

  • Windows 7 Ultimate (64-bit) Create a System Image Failure (error code: 0x80780119)

    Hello, I recently bought a new 1 TB hard drive, and I want to move everything from my original 250 GB to the new one. I have read from numerous sources that Creating a System Image through Windows 7, and then restoring that system image using the Win

  • How do I save PDF files on my iPad to read later?

    How can I save PDF files from a website on iBooks to read later?

  • Using Droid Incredible internationally

    I know there are a lot of different posts regarding using the HTC Droid Incredible in international CDMA locations. I am travelling to Israel which is a CDMA country. I plan on using my phone for wifi and GPS only (i have cached google maps around th

  • IOS 8 rearrange activities not staying put

    When I rearrange the Activities order on the iPhone 6, they don't stay in the same order after I quit app. This happens in every app (Safari, Photos, etc). Any idea why the order is not staying in memory?

  • New ipod on the fritz!

    my first ipod. the software is installed and with updates correctly on the computer. and when i plug the usb in the ipod flashed "do not disconnect" for hours on hours. the battery is fully charged. ive re-installed the program just incase. and went