Passing objects between Servlets and JSP

Hi,
I have passed a ResultSet from a Servlet to JSP using RequestDispatcher forward(). I can access the ResultSet in the JSP page. How can I now pass this ResultSet into another JSP page once the form has been submitted?
Thanks in advance.

You should never passing expensive resources like ResultSet around like that. This indicate an open DB connection somewhere while it should already be closed at this stage.
Read on about the DAO pattern and make use of servlets and beans.

Similar Messages

  • Pass Object Between Applet and JSP Page

    Hi all,
    How can I pass an Object(such as Vector, File), rather than just string to the Applet from a JSP page?
    Thank you.

    I used Base64Encoder and Base64Decoder from servlets.com utilities.
    * convert any serializable object to a String
    public synchronized static String objectToString(Serializable obj) throws Exception {
        ByteArrayOutputStream bos = new ByteArrayOutputStream(100);
        ObjectOutputStream oos = new ObjectOutputStream(bos);
        oos.writeObject(obj);
        byte[]bytes = bos.toByteArray();
        bos = new ByteArrayOutputStream(); //to save the encoded String
        Base64Encoder enc = new Base64Encoder(bos);
        enc.write(bytes);
        String encodedString = bos.toString();
        //close all
        enc.close();   
        oos.close();
        bos.close();
        return encodedString;
    * Recreates the object from the encoded String
    public synchronized static Object stringToObject(String str) throws Exception {
        ByteArrayInputStream bis = new ByteArrayInputStream(str.getBytes());
        Base64Decoder dec = new Base64Decoder(bis);
        ObjectInputStream ois = new ObjectInputStream(dec);
        Object obj = (Object)ois.readObject();
        ois.close();
        dec.close();
        bis.close();
        return obj;
    }

  • How to pass objects between servlet services

    I wanted to pass an object from one service to another service and that object must be visible only for these two services. I don't want to use session.setAttribute or session.getAttribute to do this. When I use request.setAttribute and request.getAttribute methods not helping me to do this. Is there a way to do this?
    Between, how these request.setAttribute and request.getAttribute methods useful?
    regds
    -raju

    Actually, I set attribute in one of the service
    methods. Within that service method a form will be
    there. After pressing submit button in that form, the
    other service will be called. Does it mean that both
    the services are not in the same request scope, even
    if they are in the same servlet?They are on different request scopes. Each time the user clicks a link, they make a request to the server. The server processes the request creates a response and send that response back to the client. Once the response it sent (and finished being sent) the request is done with, and anything is request scope goes out of scope. When the user clicks the submit button, a NEW request (and request scope) is made to handle that ...
    Your best bet is to use a session here. It is the easiest way to maintain state between requests. That is what the session is designed for.

  • How to pass values between applet and jsp

    I have a jsp calling an applet which needs to return value to the calling jsp based on the action. Once the applet returns value to the calling jsp, I need to put that value into the session so that I can use it for the other pages. Could anyone have suggestion how to do it. I am new to applet development. Appreciate your help.

    Why does it have to send the value back via the same JSP? Why not create a servlet to take input from the applet?

  • Can objects be passed between Applets and JSP?

    Can objects be passed between Applets and JSP? If so how? Thanks in advance.
    Scott

    see if this helps,
    http://forum.java.sun.com/thread.jsp?forum=54&thread=136847

  • Differences between WL or Netscape for Servlets and JSP's

    What are the advantages / disadvantages of running Servlets under WL,
              vs. say, running them in Netscape's servlet engine? Assuming EJB
              container is run separately, either one of these could make calls to the
              WL EJB server, so perhaps it would be simpler and faster to run servlets
              and JSP's under Netscape, and have them call via t3 into a weblogic
              server for EJB's?
              Thoughts
              david
              David Michaels <[email protected]>
              Director of Technology
              ShockMarket Corporation (650) 330-4665
              [david.vcf]
              

    David,
              One of the major reasons to run your servlets on Weblogic is that we have an
              optimization that allows us to pass by reference objects when calling from
              servlets to EJB. This makes things much faster.
              A number of our customers, in addition, have seen performance problems when
              using other servlet engines. It just seems to cause problems due to their
              threading models etc.
              Finally, our servlet engine is by far the most mature and robust on the
              market today. Our JSP implementation is also the best in terms of
              performance.
              Thanks,
              Michael
              Michael Girdley
              WLS Product Manager
              David Michaels <[email protected]> wrote in message
              news:[email protected]..
              > What are the advantages / disadvantages of running Servlets under WL,
              > vs. say, running them in Netscape's servlet engine? Assuming EJB
              > container is run separately, either one of these could make calls to the
              > WL EJB server, so perhaps it would be simpler and faster to run servlets
              > and JSP's under Netscape, and have them call via t3 into a weblogic
              > server for EJB's?
              >
              > Thoughts
              >
              > david
              >
              > --
              > David Michaels <[email protected]>
              > Director of Technology
              > ShockMarket Corporation (650) 330-4665
              >
              >
              

  • Hi i wrote a question a weeks ago about servlets and JSP

    I thank to jimbal2 for help me on the topic "how to comunicate from servlet to a JSP and viceversa?", the solution was:
    You have a mechanism called "forwarding", with which you can pass control from one resource (servlet/jsp) to another resource (servlet/jsp). You do this using a RequestDispatcher, which you can get from the HttpServletRequest object. If for example you want to forward to "index.jsp" which is in the root of your web application, you would do this in your servlet:
    RequestDispatcher rd = request.getRequestDispatcher("/index.jsp");
    rd.forward(request, response);
    return;
    (watch the return statement, you must manually return after a forward, or else the servlet will continue executing!). A forward will NOT create a new request, the same request is passed to the new resource (to create a new request, use a redirect in stead, also done with the RequestDispatcher).
    To pass objects between the two resources when doing a forward, use request.setAttribute(), request.getAttribute() and jsp:useBean.
    but i have some other questions, and these are :
    so i've to do this with sessions and everything i want to pass to: for example my application is a servlet based, from a servlet to a JSP so i have to do it with:
    RequestDispatcher rd = request.getRequestDispatcher("/servletToJsp.jsp");
    rd.forward(request, response);
    return;
    if its from a JSP to a servlet it is the same way?, if i want to pass the session from one to another and viceversa how do i do that?,and its possible to import into a JSP a class that isn't a bean? because like i wrote here my appplication is a servlet-based but i want to insert new JSPs so thanks for your help and if its possible to respond my questions.

    but i have some other questions, and these are :
    so i've to do this with sessions and everything i want to pass to: for example
    my application is a servlet based, from a servlet to a JSP so i have to do it with:
    RequestDispatcher rd = request.getRequestDispatcher("/servletToJsp.jsp");
    rd.forward(request, response);
    return;
    if its from a JSP to a servlet it is the same way?, JSP is actually generated as a HTML.
    You can simply use a HTML form to submit data to a Servlet
    if i want to pass the session from one to another and viceversa how do i do that?,http://java.sun.com/products/servlet/2.2/javadoc/javax/servlet/http/HttpSession.html
    session.setAttribute("id",123);
    session.getAttribute("id");
    Similar to request.setAttribute() but last for a session.
    and its possible to import into a JSP a class that isn't a bean? because like
    i wrote here my appplication is a servlet-based but i want to insert new JSPs http://java.sun.com/developer/onlineTraining/JSPIntro/contents.html#JSPIntro3
    You can import java.util.*, java.io.* , etc.
    so thanks for your help and if its possible to respond my questions.See if it helps

  • Juggle between jstl and jsp!

    I have a list of items and whose size is obtained by jstl as follows:
    <c:set var="num" value="${fn:length(form.namesList)}"/>I have to find the number of blocks using jsp and I am trying as follows which is giving jspException.
    <%int numCols = (int)Math.ceil( num / 10.0);%>Can anyone tell me the problem over here?
    I need to use numCols to display my results using jstl as follows:
    <c:forEach var="y" begin="${1}" end="${numCols }">
    </c:forEach>Can juggle between jstl and jsp like this?

    This depends on the version of JSP you are using:
    If you are using JSP 2.0 (like Tomcat 5), make sure you have downloaded and installed JSTL 1.1 and set the web.xml up to use the Servlet 2.4 specs. Then the code you wrote should work.
    If you are using JSP 1.x (like Tomcat 4 and below), make sure you have JSTL 1.0. Then you can only use EL (the Expression Language used to translate ${...} expressions) inside JSTL.
    If you want to use EL inside your custome tags, look through the Apache Jakarta sight. Somewhere they have an ELExpression translator (a couple of classes actually - whose full names I forget). These classes will let you take the ${...} expressions in as strings, pass them through the translators and get the correct objects back out.
    Or you could go a simpler root:
    <mob:whatever object="test" name="newname" />
    then in your custom tag:
      MyType test = (MyType)pageContext.findAttribute(object);
      test.setName(name);

  • How to get an ArrayList Object in servlet from JSP?

    How to get an ArrayList Object in servlet from JSP?
    hi all
    please give the solution for this without using session and application...
    In test1.jsp file
    i am setting values for my setter methods using <jsp:usebean> <jsp:setproperty> tags as shown below.
    After that i am adding the usebean object to array list, then using request.setAttribute("arraylist object")
    ---------Code----------
    <jsp:useBean id="payment" class="com.common.PaymentHandler" scope="request" />
    <jsp:setProperty name="payment" property="strCreditCardNo" param="creditCardNumber" />
    <%-- <jsp:setProperty name="payment" property="iCsc" param="securityCode" /> --%>
    <jsp:setProperty name="payment" property="strDate" param="expirationDate" />
    <jsp:setProperty name="payment" property="strCardType" param="creditCardType" />
    <%--<jsp:setProperty name="payment" property="cDeactivate" param="deactivateBox" />
    <jsp:setProperty name="payment" property="fAmount" param="depositAmt" />
    <jsp:setProperty name="payment" property="fAmount" param="totalAmtDue" /> --%>
    <jsp:useBean id="lis" class="java.util.ArrayList" scope="request">
    <%
    lis.add(payment);
    %>
    </jsp:useBean>
    <%
    request.setAttribute("lis1",lis);
    %>
    -----------Code in JSP-----------------
    In testServlet.java
    i tried to get the arraylist object in servlet using request.getAttribute
    But I unable to get that arrayObject in servlet.....
    So if any one help me out in this, it will be very helpfull to me..
    Thanks in Advance
    Edward

    Hi,
    Im also facing the similar problen
    pls anybody help..
    thax in advance....
    Litty

  • Servlet and JSP in OAS

    I'm developing web application with OAS
    4.0.8.1 and JDeveloper 3.0 and I want to call
    JSP from servlet using "RequestDispatcher".
    I downloaded JSP for OAS from www.olab.com.
    In the Release note, there is a description
    about RequestDispatcher, but I cannot
    understand about details.
    In what configuration can I use servlet and
    JSP together with RequestDispatcher. Anyone
    scceeded about that?
    null

    wan (guest) wrote:
    : Hi everyone,
    : I am using OAS 4.0.8 on Solaris 2.6. After viewing servlet
    : and JSP samples, I am kind of confuse whether OAS supports the
    : following options
    : 1. JSP
    : 2. servlet chaining
    : 3. running JDeveloper DB Servlet wizard
    : (oracle.jdeveloper.servlet.*) and Java Business Objects
    : (oracle.jbo.rt.cs)
    : Thank you for your time.
    I found a white paper 408newfead.pdf, that says under "Future
    Directions" that it will add jsp support. I read somewhere (I
    can't remember where exactly :( ) that said 4.0.8.1 would
    support
    JSPs. I don't know if this release is out yet.
    I wish Oracle would get with the times and put out a product that
    is consistent with the technology they are touting as the
    future.
    Having us download Suns server to run servlets and JSP is
    ridiculous for the worlds second largest software company!
    null

  • Use context to pass value between JPF and Java Control

    hi,
    Can we use context to pass value between JPF and Java Control? It works if i m using InitialContext in the same machine but i dun think it will works if i put Web server and application server in different machine. Anyone have an idea how to do it?
    I also want to get the method name in the onAcquire callback method. Anyone knows how to do this?
    thks
    ?:|

    Hi.
    Yoy can the next options for make this:
    1. Pass your values in http request.
    example: http://localhost/index.jsp?var1=value1&var2=value2&var3....
    2. You can use a no visible frame (of height or width 0) and keep your variables and values there using Javascript, but of this form, single you will be able to check the values in the part client, not in the server. Of this form, the values of vars are not visible from the user in the navigation bar.
    Greeting.

  • What do I need to compile and run Servlets and JSP?

    Hi there,
    What do I need to run Servlets and JSP? I am developing on a Windows platform.
    As far as I know, Tomcat and JDK is needed. My JDK (1.3rc1) cannot seem to compile servlet files (javax.servlet.* not found)
    Can anyone please advise?
    Thank you in advance.

    If you mean "in a month", then the answer is "afaik, no.", sorry.
    If you need something comfortable, you better should buy one of these heavy-weighters like Weblogic, or WebSphere. Cost some $$$$'s, though (between 2000-10000. I guess).
    For servlets (and ejb's too), there is no "easy and quick" solution. You probably should think about buying a freelancer or such, which already has the appropriate know-how.

  • Pass data from servlet to jsp using sendRedirect

    Hi,
    I am passing data from servlet to jsp using forward method of request dispatcher but as it doesn't change the url it is creating problems. When ever user refreshes the screen(browser refresh) it's re-loading both servlet and jsp, which i don't want to happen. I want only the jsp to be reloaded.
    Can I pass data from servlet to jsp using sendRedirect in this case. I also want to pass some values from servlet to jsp but without using query string. I want to set some attributes and send to jsp just like we do for forward method of request dispatcher.
    Is there any way i can send data using attributes(without using query string) using sendRedirect? Please let me know

    sendRedirect is meant as a true redirect. meaning
    you can use it to redirect to urls not in your
    context....with forward you couldn't pass information
    to jsps/servlets outside your own context.Actually, you can:
    getServletContext().getContext("/other").getRequestDispatcher("/path/to/servlet").forward(request, response)I think the issue here is that the OP would like to have RequestDispatcher.forward() also update the address in the client's browser. That's not possible, AFAIK. By the time the request is forwarded, the browser has already determined the URL of the servlet, and the only I know of way to have the browser change the URL to the forwarded Servlet/JSP is to send a Location: header (i.e. sendRedirect()). Remember that server-side dispatching is transparent to the client. Maybe there's some tricky stuff you can do with JavaScript to change the address in the address bar without reloading the page?
    Brian

  • (UIX XML) Sharing Connection objects between BC4J and custom java.

    If I have a UIX XML page that contains some BC4J application modules, then in the event handler I call [public static EventResult handleMyEventEvent (BajaContext context, Page page, PageEvent event..) ], which in turn calls some java classes I have written that take a java.sql.Connection object and access the database doing some updates/inserts with this Connection object (via JDBC)....HOW CAN I USE THE SAME TRANSACTION AS WAS USED IN THE BC4J APPLICATION MODULE...i.e. CAN I SHARE THE CONNECTION OBJECT BETWEEN BC4J AND MY OWN JAVA CLASSES THAT USE JDBC?
    What are the best ways to share such a transaction?
    Thanks,
    Paul.

    Would it be easier to use a custom method on the bc4j Application module?
    Take this scenario...
    1. User opens UIX XML web page which opens a bc4j App Module..it has a VO based on all employees.
    2. User presses the add button and a new employee is created (using the bc4j App Module).
    (Notice: no commit yet!)
    3. User presses the submit button...fires event REVIEW_SALARY.
    4. This event is 'handled' in the event section of the UML XML...it calls:-
    public static EventResult handleREVIEW_SALARYEvent (BajaContext context, Page page, PageEvent event)...
    5. I now want to call a java class I wrote that computes an employees new salary and updates the employee record with this new salary. This update will fail unless it is part of the same transaction as the one used by the bc4j App Module (that inserted the new employee).
    How best to proceed from here?
    How about having a method on the bc4j App Mod's VO called 'reviewSalary'? Calling this would use the same transaction? I could then call my java class from within the VO's method? However do I still have the same problem in that my java class expects to be passed the connection object?
    The approach you suggested previously seems a touch dangerous....in that these are not 'publically exposed'...and a new release of JDev may break my code.
    Thanks,
    Paul.

  • Difference between servlet and filter

    difference between servlet and filter

    Its not a secret you know; if you just read a little about what they are used for, you answer your own question plus many more to follow.
    Servlet: http://en.wikipedia.org/wiki/Java_Servlet
    Filter: http://www.oracle.com/technetwork/java/filters-137243.html

Maybe you are looking for

  • Erro 8B260 (Processo de Entrega Futura)

    Bom dia, Pessoal! Estou com um problema no processo de devolução de entrega futura. Realizei a entrada da nota de fatura normalmente atraves da MIRO e da nota de remessa atraves da MIGO (mov 801). O fornecedor nos enviou as notas de Fatura e Remessa

  • How can we get the location from location area code?

    Hi All, i have an application which successfully runs on Motorola L6 and it gives me the cell-id, Location area code, and Mobile Network Code, and Mobile Country Code. Now I want to know how can I get the location ( I mean the name of the location) t

  • Bought elements 10 last month and can't use the edit feature.

    So I got elements 10 with a Wacom Bamboo Capture around April 23rd last month. I created a new adobe id and signed in. It asked me to update my account and add my birthday, personal URL for photoshop, and agree to the terms. Everytime I've tried to d

  • Need Help With Spam Proof Email Form

    I am making a new web site using iWeb, .Mac, personal domain and forwarding from my commercial host. I want to make an email contact form that spammers cannot hijack and use to deluge use with spam. I have another web site that was created with Dream

  • JMenuItem ActionEvent Dinamically - Problems

    Hi, friends I am trying to use a JMenu and a JMenuItem wich are dinamicaly constructed getting data using a Oracle's Database Table. They are working fine, but I can't figured out how can I add ActionEvent dinamicaly. The piece of my code is down her