Looping  a JavaBean through a JSP/Servlet possible?

I have a webapp that has a JSP page that shows data in an "HTML form" based on a JavaBean passed in from a Servlet. When the user submits the form (possibly with changes), I would like to be able to send this exact same JavaBean (with original data and possibly some modified data) back to the original Servlet. I can't seem to find any examples that do this. I don't want to do this at the "session or application" scope if possible. Am I correct in thinking that this is not something that can be done in "one" request scope. I would think that there are two separate requests being made here for one "loop". One request that's forwarded into the JSP, and another that's created by the form submission. Can anyone verify that this is indeed possible, and point me in the right direction. Or if there is a reason that it's not possible, please explain why. Thanks in advance.

Whenever your browser submits, or you navigate to a page, or you do a redirect, you are creating a new request. You are correct in thinking that you cannot retain the original bean when you don't want to use the session, you'd have to take the form fields and recreate your bean.
The session is for storing temporary data across multiple requests, which is apparently what you want so I don't really understand what your problem with it is.

Similar Messages

  • Generating pdf file through jsp/servlet

    One of the MIME types for servlets/JSP response is "application/pdf".
    After setting Content-Type header "application/pdf" in servlet by
    setContentType() method, I am unable to get the output in a pdf file.
    Please let me know how I can generate a pdf file through Servelt/JSP
    response.
    Thanks.

    We've got a product which allows you to convert XML to PDF from a JSP. It doesn't currently take straight HTML, but the XML syntax we use is pretty similar (you can use CSS2 and so on), so for many pages it doesn't take a lot of conversion.
    If you check out http://big.faceless.org/products/report/examples.jsp you'll see a few examples, two of which are dynamically run from a JSP. There's a free trial download for you to test with (although it's a commercial product).
    Hope that helps.
    Cheers... Mike
    Mike Bremford - CTO mike at big.faceless.org
    Big Faceless Organization http://big.faceless.org

  • Is it possible to include JSF into JSP-Servlet application?

    I have an existing JSP-servlet application. I am wondering if it is OK to add new pages to this application in form of JSF?
    Thanks

    Just learn JSF and it will all be clear.
    They can perfectly co-exist and you can perfectly link or redirect from one to other (plain GET requests), you can perfectly share the same session and application scoped attributes, but for POST requests (forms submits) from JSP to JSF or vice verse you just need to understand how the one handles/expects the request parameters and that kind of stuff.

  • Monitor my jsp-servlet application through the jmx

    heloo,
    i am new in JMX. and i want to manage(or monitor) my jsp-servlet application. there lots of
    servlets and jsp files. its is running in tomcat. i made simple demo application which
    is given by oracle tutorial. but it is just for one interface and its implementations so how
    can i monitor my whole jsp-servlet application by JMX.
    i want to Monitor three things
    Memory
    JVM
    Thread
    Thanks...

    Hi,
    I fixed my problem by setting the system wide variable (WindowsXP)
    CLASSPATH to r:\\dealershop\\WEB-INF\\classes.
    Thanks,
    Andrea
    andrea costantinis wrote:
    Hi,
    I developed a JSP/servlet test application that makes
    use of kodo 2.2.3 STANDARD EDITION for its persitence.
    I successfully compile and annotate the application.
    I am also able to successfully generate the db
    schema with schematool.
    Unfortunately, when I run the application using
    Resin 2.0.2, Kodo is unable to initialize properly.
    Initially it was not able to find \"system.prefs\" file.
    I fixed that by putting \"system.prefs\" in WEB-INF\\classes.
    Unfortunately, Kodo is still unable to initialize and
    gives the following message:
    The system could not initialize; the following registered
    persistent types are missing metadata
    or have not been enhanced:
    [class com.dpov.purchaseorder.PurchaseOrder,
    class com.dpov.catalog.Product,
    class com.dpov.uidgen.counter.Counter,
    class com.dpov.catalog.dao.jdo.CategoryHierarchyEntry,
    class com.dpov.catalog.dao.jdo.CategoryHierarchyDAO,
    class com.dpov.pricelist.PriceInfo,
    class com.dpov.pricelist.PriceList,
    class com.dpov.catalog.Category,
    class com.dpov.lineitem.LineItem,
    class com.dpov.dealer.Dealer,
    class com.dpov.user.User,
    class com.dpov.customer.Customer].
    I use \"system.jdo\" to describe metadata for the enhancer.
    I tried to put it both in WEB-INF\\lib and WEB-INF\\classes but
    it still fails.
    Please note that:
    1) my classpath variable is not set
    2) my application\'s class file are in WEB-INF\\classes
    3) kodo jars are in WEB-INF\\lib
    4) mysql jdbc driver is in WEB-INF\\lib
    5) system.prefs is in WEB-INF\\classes
    6) system.jdo is in WEB-INF\\classes
    Thanks in advance,
    Andrea

  • Jsp versus JSP/SERVLET

    Hello folks! :)
    First of all, I would like to apologize for posting such a question. I suppose with hardly any doubt that it has been raised a lot of times and I feel a little bit ashamed to put it another time... but fact is that I browsed the forum and did not found any real complete and technical answer.
    So, here is my question:
    I have to convince my technical superior (with concrete fact, numbers if possible!)that using SERVLET/JSP is a better way than using only JSP (which is the way they do thing at the time I post this message - everything is done in JSP).
    I did not found any "rocking" argument that demonstrate the benefits of using jsp for application.
    Boss said me "Jsp is just hidden SERVLET, so why not using them" and "we do not have complicated FORMS submission to treat, so JSP are good enough." and "graphical department doesn't work a lot on HTML. So no prob with scriplets".
    I suppose it's ok for now and for "small" projects; but I sense that in the coming future, that will probably become a problem with bigger project.
    So I would like to convince them to start working with servlets now, to avoid future waste of time!
    Thanks or your wise upcoming answers!

    well, there is a fact that servlets and jsp can be used for exactly the same purpose. A JSP page is through a JSP engine transformed to a servlet. You just put servlet code inside the <% and %>. However, the benefit of using servlets is that it is more like pure java-code, and clean from annoying tags. Using JSP also requires you to learn about the functionality behind tags. Also, in using JSP there are more difficult to control errors. In my experience it is really difficult to know where the fault lies in the JSP compared to the servlet.
    I think that it seems like you are quite convinced that servlets are the right choice, and this is what matters if you are the developer.
    Good luck,
    M

  • How can i display data on tha same page in jsp/servlet

    Hello friend,
    I am storing 50 items in a dataBase. i ve two buttons/links name previous and next. i ve to display 10 items each time in the same page when i click next button and the revrese for previous. through JSP/Servlet.
    Any suggestions will be appreciated.
    chintan anand

    I'm not sure this is the best practice... try to add the item in the arraylist, then when u click next button, add 10 to the counter. subtract if it is a previous button. thats it!
    ex..
    for(int x=counter;x<=arraylist.lenght();x++)
    ....print item here......
    }

  • How can I pass an ArrayList from a JavaBean to my JSP ?

    Hi,
    I have developed a java bean that gets info from a database in the form of an ArrayList called values.
    private ArrayList values = new ArrayList();I have a method in the bean that returns this ArrayList
    public ArrayList getValues() {
        try {
          ResultSetMetaData meta = rs.getMetaData();
          while (rs.next()) {
            for (int i = 0; i < meta.getColumnCount(); i++) {
              Object ob = rs.getObject(i + 1);
              if (rs.wasNull()) {
                ob = null;
              keys.add(meta.getColumnLabel(i + 1));
              values.add(ob);
        catch (Exception ex) {
          System.err.println("Error");
        return values;
      }I am new to this and am confused as to how to get my ArrayList back on a page that uses my bean.
    I can get it as a String on my jsp page that uses the bean
    <%= testBeanId.getValues() %>
           <%=this.toString() %>but that's not really what I want. If I try and use a for loop to go through values
    for(int i = 0; i < values.size();i++){
        out.println (values.get(i));
    }it complains that it cannot find values.
    Any ideas ? I am really new to this, so any help is appreciated.

    put the arraylist in the session and get it in the jsp.
    session.setAttribute("apps",values);
              ArrayList dataProfile = (ArrayList)session.getAttribute("apps");
              for(int j = 0; j < dataProfile.size(); j++)
              ApplBean app = (ApplBean)dataProfile.get(j);
              String app = null;
              if (app.getAppName() != null) {
                   app = app.getAppName();
              }

  • Using JavaBeans in a JSP Page

    I wan't to know the advantages and disadvantages of using JavaBeans in a JSP page.
    Like for example general traditional approach for a database connection
    is to create a connection and access the database from that and close the connection
    at the end of the page, instead of the If I use a common connection bean for making connections,
    is that suggestable and then when should i close the connection then.
    One good application of JavaBeans is using a Set and Get methods for form fields in
    a registration form to get back the values.
    So may i know how best can we use the JavaBeans other than this application.
    ThanX in advance,
    kiran
    [email protected]

    I believe putting processing and query code in the JavaBean was one of the reasons for putting JavaBeans support in JSP in the first place. The original idea was to use the setXXX methods to populate the bean's data from the posted form, then do the processing (or database query), then use the getXXX methods to display the bean's data.
    Efficiency-wise, it's exactly the same as putting all the code in-line in the JSP page (actually, it might be a bit slower, because of the reflection required to do it.) Code-wise though, it makes the JSP easier to read.
    Of course, we have EJBs now too, which tie very closely and can match database queries almost one-to-one, one way to incorporate these is inside the JavaBean you reference from the JSP, another way from a servlet you redirect the JSP to, etc...

  • How to implement this function in JSP/Servlet env?

    Hi all,
    I working on a project, it provides functionality to upload file using JSP/Servlet. In the first JSP page, there is file location and submit button. After user select a file to upload and click submit button, a message, like "sending file to XXXX", will be shown on the screen. Once uploading and validation are done on the server-side, a successful/error msg will be shown to user.
    Here I have a question for the "sending..." msg and the successful/error msg. They should be put in one jsp page or in two separate page? how to implement them?
    Thanks for any help!
    Tranquil

    For the sending message... Well, the thing is, when you click submit, it's sending the file to the server and the server is processing it, and this is all done before the "complete" page is sent to the server. So one would need to use some Javascript on the page before the actual submit happens to show some message. This is done on Ebay when you put something for sale, you can upload an image, and there is a little popup message telling you that it's uploading, and it is removed when the process is done. Now, I'm not sure the exact details of how this works, but my educated guess is this:
    1) The onsubmit function of the form checks that the file upload fields have a value (no need to popup a message if no file upload, since that's what usually takes the time, although it could just be assumed there is a file). If a file is to be uploaded, or just want to show the message anyway, a new popup window is opened with the window.open method and the "sending" message is shown (either written via Javascript or just load a small web page to the window).
    2) The popup window, since you can't transfer the window object from the form page to the next page, has to check window.opener for some value that the success/error page would have to set. The success/error page could use it's body onload function to set a variable in it's own window object to denote that the page is loaded. The popup window can use a looping check using setTimeout or setInterval in Javascript to check for window.opener.isLoadedVariable to be present, and if so, close itself.
    I've never done that, but I see no reason why it wouldn't work.

  • 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

  • For loop to iterate through temp table in store procedure in pl/sql

    Hi,
    how to create For loop to iterate through the temporary table in the store procedure?

    Neha RK wrote:
    hi,
    its not working , i need to check each record of table and do some task using if else loop inside that for..
    if not possible to loop each row of table using for then how to use while loop.
    please helpWhat's not working? We haven't got psychic powers so we can't see the code you say isn't working.
    Please provide more information like create table statements, insert statements with test data, the code you've tried
    and the output you are expecting from the input data.
    Read {message:id=9360002} and follow the advice there.

  • Can we run external mail program from JSP / Servlet deployed on tomcat

    Hi folks,
    Had a tough time getting JavaMail API to work, finally when things seem to be working
    there were some issues with the vendor's server, so finally gave up the idea.
    On the server Apache and Tomcat are integrated via mod_jk and currently I redirect to a php page
    which acts as a helper to send mail, however for the given business needs and server's limitations
    there are potential security holes.
    So I was wondering if I could directly execute the linux sendmail program from JSP/Servlet
    as we would in a standalone java program or do we need special settings on Tomcat to execute external
    programs.
    Please let me know your views / ideas / comments on this
    Thanks in advance
    Abishek

    Hi
    It's not designed for you to be able to do this, it needs to run through 10gAS or 11gWeblogic.
    Tony

  • Can somebody explain to me how JSP, servlets, ASP work within Sun's server

    Ok, I'm only beginning to get a grip of how all this works. And I have a lot of questions and confusion.
    1.) The server that comes with J2EE, what is that server? Is it an app server that runs only servlets and JSP, with some Web server stuff so it can output some info? Is it a stripped down version of TomCat? I am having a lot of trouble with the J2EE server (the one that comes with the SDK), and that is why I'm asking, maybe I don't need it. But I really want to learn JSP's, JScripts, and Beans. How else can I go about doing that, other than all out Tomcat.
    2.) Also can I run Servlets on Microsft's IIS on a Windows 2000 machine? Do I need a special API to run servlets, or JSPs?
    So how I see it, and again, I am a newbie at this. Machines that host a website, above all needs a web server. let's say most people use Apache, and they want to run it in Linux, becuase they want to be hackers. So then do they also run Tomcat, or IIS, or Coldfusion, or a million other servers in tandem on the same machine, so that they can handle ASP, JSPs, servlets, .cmf, etc.? or do they separate the app server from the webserver and then do some sort of linking? if somebody can direct me to how all this stuff works, I would greatly greatly appreciate it.

    Sounds like you need to read the J2EE spec as well as
    the servlet and JSP specs. It helps to glance through
    sections you are interested in.
    Ok, I'm only beginning to get a grip of how all this
    works. And I have a lot of questions and confusion.
    I think for a newbie, deploying your jsp's and servlets
    to a J2EE compliant app server can be quite a headache.
    You might want to concentrate on tomcat, which does servlet
    and jsp.
    Some app servers provide a http connector for most common web servers.
    I think tomcat has a IIS connector. In this case IIS would serve static html as well as its own stuff, other things like servlets and jsp go to tomcat. I am unsure about this as I mostly use tomcat in standalone mode. You can run tomcat on windows, as it is written in java.
    >
    2.) Also can I run Servlets on Microsft's IIS on a
    Windows 2000 machine? Do I need a special API to run
    servlets, or JSPs?

  • 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

  • Sample jsp servlet bean (MVC) code

    We want to look into the JSP/Servlet/Bean area for our next project. We wish to understand the technology and as such want to hand build simple applications, and as such do not want to use JDeveloper just yet.
    We have searched and searched for suitable material but cannot anywhere find a sample application that :
    A. Lists contents of a databse table
    B. Each item in trhe list is a link to a page that allows that item, to be edited.
    C. A new item can be added.
    D. Uses the MVC model of JSP/Servlet and bean (preferably with no custom tags)
    There are examples that are too simplistic and do not cover the whole picture. Having spent over 100 GBP on books lately, only to be disappointed with the examples provided, we need to see some sample code.
    The samples provided by Oracle are too simplistic. They should really have provided ones built around the EMP and DEPT tables.
    Anyone know where we can get hold of this sample code.

    At the risk of sounding really dumb the examples are just too complex. There does not appear to be anywhere on the web where I can find a simple JSP/servlet/bean example of the type I described. There is enouigh material describing each individual component, but what I need is an example to cement the ideas, but the ones suggested are too much for a newbie. Even the much vaunted Pet Store thingy causes my eyes to glaze over.
    I dont expect anyone to have written something with my exact requirements, but surely to goodness there must be something that:
    1. On entry presents a search form on a table (e.g. EMP)
    2. On submission list all rows in EMp matchiung the criteria.
    3. The user can either click the link 'Edit' which opens up a form dispalying the row allowing the user to edit and save the changes, or click the 'New' button to show a blank form to create a new EMP.
    All this via a Controller servlet, with the database logic handled by a java bean, and all the presentation done via JSP.
    To me this is the most obvious and instructive example of this technology, but after days of trawling the web, and looking through a number of books, I cannot find such a thing.
    CGI with Perl DBI/DBD was a breeze to work with compared to this stuff ..... maybe ASP with SQL/Server would be a more fruitful use of time.

Maybe you are looking for