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.

Similar Messages

  • 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.

  • 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.

  • Urgent: problem with sharing HttpSession  object between Jsp and servlets.

    Hi,
              We are using weblogic 6.0 sp2.
              I m setting a particular object in session in a servlet using
              session.setAttribute() but when i try to retrieve that object using
              session.getAttribute() in a jsp page the value of that object is null. Is
              there any way to configure HttpSession in weblogic so that jsps and servlet
              can share the same session? Or any workaround for this problem.
              Any help in this regard is appreciated.
              Thanks
              -Shree
              

    Just a guess, but it sounds like you have cookies turned off and are not
              using encodeURL. Try enabling cookies and see if that solves the problem.
              Also, it is generally good practice to use encodeURL to protect yourself
              from users who disable session cookies.
              Here's how we use encodeURL in our Servlets:
              gotoPage("/jsp/someJSP.jsp");
              private void gotoPage( String address,
              HttpServletRequest request,
              HttpServletResponse response )
              throws ServletException, IOException
              RequestDispatcher dispatcher =
              etServletContext().getRequestDispatcher( response.encodeURL( address ));
              dispatcher.forward( request, response );
              "Shree Unde" <[email protected]> wrote in message
              news:[email protected]..
              > Hi,
              > We are using weblogic 6.0 sp2.
              > I m setting a particular object in session in a servlet using
              > session.setAttribute() but when i try to retrieve that object using
              > session.getAttribute() in a jsp page the value of that object is null. Is
              > there any way to configure HttpSession in weblogic so that jsps and
              servlet
              > can share the same session? Or any workaround for this problem.
              > Any help in this regard is appreciated.
              > Thanks
              > -Shree
              >
              >
              

  • Difference between jsp and servlets

    Can any body tell me the difference b/w jsp and servlets.
    As i know one difference is to seperate the java code from html. Is there any other difference. please...

    Servlets are a way to run java on a server. They don't necessarily need to be about HTML or even HTTP. You can write servlets that generate images rather than HTML, for example.
    JSP is a way to create servlets that generate HTML. They get translated into servlets (special-purpose servlets). This is sort of glossing over the details -- the power of JSP is that, by being an intersection between HTML and executed Java code, they can provide a way to clearly differentiate between the two.
    That's a way of looking at it anyway.

  • What is the diff between jsp and servlet

    is thr any other difference betwwen jsp and servlet, tht: jsp is automatic generated servlet and jsp has different types of tag, due this we have write less amount of code.any other technically difference between these two?

    As you mentioned JSP automatically gets converted into a Servlet and then compiled. From the server's perspective other than the transformation process, there is no real difference.
    However, in coding there are some minor differences such as additional access to pre-defined variables and different syntax for some minor things such as imports and etc.
    Perhaps somebody else more knowledgeable can fill you in further.
    Hope that was helpful.

  • Choice between JSP and Servlet

    I am new to JSP and Servlet. I know JSP container will convert JSP to servlet
    eventually. But in application development's standpoint, anything can be
    done in servlet can also be done in JSP? Some people told me we can
    use the combination of both in one application.
    My question is in what situation we use JSP alone, servlet alone, or
    combination of both??
    Please advise. Thanks!!

    Use a combination of both.
    Your Web application should have a single servlet that all HTTP requests are POSTed to. All the servlet does is act like a traffic cop: it figures out what the request is, delegates to other objects that do the work, and forward the result to the next JSP, whatever that is. It's called a front controller servlet.
    The JSPs should just be pure dynamic presentation. Everything displayed in the pages should have been generated by the servlet and its helper classes. No database queries, etc. Your JSPs will be a lot better off if you learn JSTL and eliminate all scriptlet code.
    Check out frameworks like Struts.

  • Data in JSP and servlet

    Hi all,
    Now i have a jsp page for register when user summit at form.
    I would like to go to the another jsp page that show user data.
    After that if user confirm data the form will throw data to servlet.
    What should i do in this solution.How can i pass data from first JSP
    to second JSP and finally to servlet because the data must contain
    in form.So how the data in first JSP page can be passed to servlet through
    second JSP.Some data will not be shown in second JSP page.
    Urgent!
    Please, Please,Please
    I know that sun has a lot expert and kindness people.

    Nobody help me
    OK Do you have some suggestion for this solution?
    What is method should i do?Please advice me,other method.

  • WSRP - Pass Custom Data between Consumer and Producer

    Hello All,
    I am having a couple of queries with respect to Custom Data Transfer. Consider I have a Map of values which I need to transfer between both Consumer and Producer.
    For eg: the map that Consumer sends would contain "firstName", "lastName", etc... On the other hand Producer needs to do some business function based on the data and add more values to the map like "rewardPoint" etc....
    On Consumer Side:
    I have choice to use Backing File or IGetMarkupInterceptor to implement the preInvoke to pass the data using SimpleStateHolder.
    Question: I am not able to send a simple Serializable POJO Object... I can only send primitive / default java objects like Strings, Maps of String etc. Is my understanding correct?
    On Producer side:
    I am able to receive the Custom Data from request. No problems. Now how to send more data from Producer to consumer. I need to add the "rewardPoints" into the map and send back.
    My understanding is that if the Producer puts any values into StateHolder objects, Consumer will receive it in IGetMarkupResponseContext object in the Interceptor's postInvoke method.
    Question: How do I get a handle to the IGetMarkupResponseContext object @ Producer end???
    Question: Do I need to write some interceptors on Producer end? If so which file I need to use?
    Any help / pointers would be greatly appreciated.
    Thanks,
    Paz

    Hi All,
    I tried to set the data in the producer using the following command
    SimpleStateHolder stateSimpleOuterReq = (SimpleStateHolder)request.getAttribute(MarkupRequestState.KEY);;
              if (stateSimpleOuterReq == null) {
                   SimpleStateHolder state = new SimpleStateHolder();
                   state.addParameter("name", "data1");
                   request.setAttribute(MarkupResponseState.KEY, state);
    I am not able to retrieve the same in consumer.
    The above is a WSRP struts request.
    I also tried setting the data by unwrapping the request in producer and still value is null in consumer :-(
              HttpServletRequest requestq = (HttpServletRequest)((HttpServletRequestWrapper) request).getRequest();
              SimpleStateHolder stateSimpleReq1 = (SimpleStateHolder)requestq.getAttribute(MarkupRequestState.KEY);
                   if (stateSimpleReq1 == null) {
                        SimpleStateHolder state = new SimpleStateHolder();
    state.addParameter("name", "data1");
                        requestq.setAttribute(MarkupRequestState.KEY, state);
    Please help me in resolving the issue. Correct me if i am doing anything wrong.
    Thanks
    T. Deena
    Edited by: user11261911 on 12/06/2009 19:49

  • How can I pass a variable between JSP and Role Form

    I need to pass a variable from (a copy of) applicationmodify.jsp to the IDM Role Form so that the variable is available within the Role Form at display. We've tried getAttribute and setAttribute modifying both the Role Form and the applicationmodify JSP and can get the form to the role form but not accessible but have had no other success. Has anyone had any success in doing this? Any suggestions would be appreciated.

    if by _root level you mean you're loading something into
    _level0 you can't won't be able to use the localconnection. the
    sharedobject is your only option.

  • Passing parameters between JSP and Servlet

    The scenario is as follows:
    There is a JSP page that sends a string as a hidden parameter to a servlet:
    <input type="hidden" name=<%= Book.NAME %> value=<%= book.getName() %> >
    In the servlet there is a print statement that checks the parameter value:
    System.out.println("Book name: "+request.getParameter(Book.NAME));
    The problem is as follows: if the name of the book consists of more than one word
    such as "Servlets and JSP", the print statement will print only Servlet.
    If the JSP page passes a string directly as shown here:
    <input type="hidden" name="Test" value="Test String" >
    The servlet will print the complete string: Test String
    The same problem appears if the string is passed between two JSP pages.
    Any help is greatly appreciated.
    Regards,
    Basil Mahdi

    You might want to try
    <input type="hidden" name="<%= Book.NAME %>" value="<%=URLEncode.encode(book.getName(), "UTF-8")%>" >This will take care of any wierd un-url friendly charcters that might appear in the book titles such as the ' or " which may be the problem.

  • URL mapping  between jsp and servlet

    recently, I try glassfish, and I get surprised, for example My application name is HelloWorld if I have jsp action to servlet I can't use action ="servlet/myservlet1" I have to use
    action="HelloWorld/myservlet " if I put my servlet2 under test folder I can't call this servlet by servlet/test.servlet2, I have to use HelloWorld/servlet2,. I realize that is not glassfish problem , I just wonder is any one could give more expiration on servlet mapping ??
    Thank you !

    Depends on several factors. In which context and how exactly are you specifying the URL? In client context, the leading "/" brings you to domain root. In servlet context, the leading "/" brings you to context root. The HTML <a> element is relative to client context and JSTL <c:url> is relative to servlet context. That kind of things.

  • Passing Session info between servlets

    We are running WebLogic 5.1, sp 4 and Apache 1.3 on Solaris 2.6 and we are
              successfully proxying requests to the server. But we are unable to pass
              session information between servlets. We are NOT using URL encoding. We are
              instead using cookies. We believe our configuration is correct because the
              BEA example session servlet works. Does anyone have any recommendations or
              suggestions?
              Thank you,
              Jorge
              Jorge A. Martin
              Systems Analyst
              The Kinetic Group
              1950 Stemmons Freeway, Suite 3040
              Dallas, Texas 75207
              

    This is a basic misunderstanding of how Java Works:
    String name +r = request.getParameter(name +r);1) You can't use a + on the left part of an assignment operation - it must be a plain variable reference. This isn't like JavaScript where you have an eval(...) capability.
    2) Your Strings are being defined inside the For Loop, which means they will leave scope once the loop ends and you won't be able to refer to them anymore.
    3) Is there already a String value named 'name' which you are using in getParameters(name+r)? You should probably use getParameter("name"+r) instead.
    What you want to do is either put the values in an array so they are easy to access:
    String name[] = new String[value1];Then loop through the parameters to assign values:
    for(int r = 0; r< value1; r++) { //Start at 0 to value1-1 because arrays are 0 based.
      String nameParam = "name"+ (r+1);
      name[r] = request.getParameter(nameParam);Now I can access the names in order:
    name1 via name[0]
    name2 via name[1]
    name3 via name[2]
    etc...Before going any further I would stop working on Servlets and go back to some good Basic Java Tutorials and books until you get a better grasp of how the language works.

  • Passing values between jsp and php

    hi there, is it possible to pass values between jsp and
    php? i really need to find out the way if there is
    any. thanks in advance
    -azali-

    Yes, there are a few ways to do this.
    1) Think about using Cookies.
    2) Maybe use a Redirect passing the values in the Query string.
    3) Retain the data in a repository in the back end.
    4) Using Hidden fields within your pages.
    I am sure you can use these Idea's for a base to develop other methods on how to pass values back and forth from JSP -> PHP and vice versa.
    -Richard Burton

  • How to pass series of dates (between startdate and enddate) to subreport, which takes only one date as parameter

    Relatively new to Microsoft report services. I have created a report which takes a single parameter named 'SelectedDate'. This report runs fine (uses complex query of hours of the selected date and complex joins & aggregate calculations between SQL
    database tables). I created a new report with two parameters, namely, StartDate and EndDate. Also created a sql stored procedure which gives all dates between StartDate and EndDate. Added subreport to this report which calls my first report and defined 'SelectedDate'
    parameter to get the value as "=First(Fields!dt.Value, "DataSet1") - where dt is the resultset of procedure called in DataSet1. When I run this report, in the subreport, all I see is the report for 'StartDate' which is the passed
    value of the first parameter. I can't find a way to pass entire array of dates as parameter, to which user can browse forwards and backwards. Any idea? Thanks in advance for your help!

    HI Visakh16..Never mind my comment..I tried it again. This time I went to the completion of previewing..and noticed that the table with DataSet1 does display dates and first report underneath but once I click any other date, it displays the subreport on
    full page and navigation back arrow (with hint 'back to Parent Report) solution is not bad..so unless you a way to achieve my desired layout mentioned above - I am good for now! Thanks for your pointer in right direction!
    One small observation for thread readers: When I published the report to the report server, the back button (back to Parent Report) which was available to me at design time, is not displayed at client's browser. Upon checking pertinent threads, concluded
    that this is known issue for years and recommendation I concluded from various threads is: Use back button of browser and it should (& did) keep the parent report page, with table with selected dates intact. A few have noticed different behaviour
    for older browser versions. 

Maybe you are looking for