Passing Arrylist from action class to jsp and parsing in jsp

I need to do the following using struts
I have input jsp, action class and action form associated to that. In the action class I will generate the sql based on the input from jsp page/action form, create a result set. The result set is stored as java objects in a ArrayList object.
Now I need to pass the arraylist object to another jsp to display. Can I put the ArrayList object in the request object and pass to the success page defined for the action? If this approach is not apprpriate, please let me know correct approach.
if this method is okay, how can I access the objects from arraylist in jsp and display their property in jsp. This java object is a java bean ( getter and setter methods on it).
( need jsp code)
Can I do like this:
<% ArrayList objList = (ArrayList)request.getattribute("lookupdata"): %> in jsp
(***I have done request.setattribute("lookupdata", arraylistobj); in action class. ***)
Assuming the java object has two properties, can I do the following
<% for (iint i=0. i<objList.size;I++){ %>
<td> what should i do here to get the first property of the object </td>
<td> what should i do here to get the first property of the object </td>
<% }
%>
if this approach is not proper, how can I pass the list of objects and parse in jsp?
I am not sure what will be the name of the object. I can find out how many are there but i am not sure I can find out the name

Double post.
http://forum.java.sun.com/thread.jspa?threadID=5233144&tstart=0

Similar Messages

  • Cannot pass parameters from action class to jsp using arraylist

    hi all,
    Im using datasource for jdbc connection.now i want to pass the selected values in action class from database to a jsp page.I want to use arraylist.But im not familar with arraylist.can anybody help .plzzzzzzzzzzz

    You can use plain javabeans to transfer the data. Check out the jsp:usebean tag. If you don't know how to do, check out the Java EE tutorial: http://java.sun.com/javaee/5/docs/tutorial/doc/ Using javabeans in JSP pages starts halfway chapter 4.

  • How to pass arraylist of object from action class to jsp and display in jsp

    I need to do the following using struts
    I have input jsp, action class and action form associated to that. In the action class I will generate the sql based on the input from jsp page/action form, create a result set. The result set is stored as java objects in a ArrayList object.
    Now I need to pass the arraylist object to another jsp to display. Can I put the ArrayList object in the request object and pass to the success page defined for the action? If this approach is not apprpriate, please let me know correct approach.
    if this method is okay, how can I access the objects from arraylist in jsp and display their property in jsp. This java object is a java bean ( getter and setter methods on it).
    ( need jsp code)
    Can I do like this:
    <% ArrayList objList = (ArrayList)request.getattribute("lookupdata"): %> in jsp
    (***I have done request.setattribute("lookupdata", arraylistobj); in action class. ***)
    Assuming the java object has two properties, can I do the following
    <% for (iint i=0. i<objList.size;I++){ %>
    <td> what should i do here to get the first property of the object </td>
    <td> what should i do here to get the first property of the object </td>
    <% }
    %>
    if this approach is not proper, how can I pass the list of objects and parse in jsp?
    I am not sure what will be the name of the object. I can find out how many are there but i am not sure I can find out the name
    thanks a lot

    Double post:
    http://forum.java.sun.com/thread.jspa?threadID=5233144&tstart=0

  • Struts - Data pass from Action class to JSP

    hello ,
    I am new to struts and have a strange question in my mind .
    How do we pass business logic data from action class to JSP.Do we use session object or any other best way to be used to pass data.
    Example scenario:
    Once the user logins into application by passing userid and password ,we need to display his open queries (from database table) on jsp.
    Components used :
    Login.jsp
    LoginForm(getter and setter methods of userid & password)
    LoginAction(get database connection,perform query to fetch user's open queries form the database)
    OpenQueries.jsp(to display Open queries on a tabular format)
    In LoginAction - We fetched user's open Queries from the database and stored them in collection object .
    My question is : what is the best way to pass Collection object from LoginAction to OpenQueries.jsp ?
    Thanks in advance...
    Ram
    Edited by: ram_76uk on Apr 10, 2008 8:21 PM

    You can use plain javabeans to transfer the data. Check out the jsp:usebean tag. If you don't know how to do, check out the Java EE tutorial: http://java.sun.com/javaee/5/docs/tutorial/doc/ Using javabeans in JSP pages starts halfway chapter 4.

  • Instead of using session How to pass the variable from action class to JSP

    Im using Struts1.2 version.Created the Sample application to get the username.Upto action class im getting the username then i have to display the username in the JSP.Is there any options rather than using session variable to display the username.

    did you check the answer in your previous thread
    Passing Variable from Javascript to Controller

  • Unable to send integer value from action class to jsp

    Hi,
    i have scenario like ,
    In my action class ,,
    DemoAction.java
    int samplevar = 3 ;
    // appending it to string since request accepts only objects.
    String sample = ""+samplevar
    request.setAttribute("sampleVar",sample );
    Demo.jsp
    <% int demovar = Integer.parseInt(request.getAttribute("sampleVar")) ; %>
    But i am unable to get the value.. what might be the reason please help...

    T.PD wrote:
    Welcome to the forum.
    855548 wrote:
    DemoAction.java
    int samplevar = 3 ;
    // appending it to string since request accepts only objects.
    String sample = ""+samplevar// You should better stick with a number object type:
    Integer sample = new Integer(samplevar );
    // or leave conversion to autoboxing (java 1.5+)
    Integer sample = samplevar ;request.setAttribute("sampleVar",10) is same as request.setAttribute("sampleVar",new Integer(10)) ;
    No explicit AotoBoxing is required as the second argumet is of java.lang.Object type. It will automatically autobox with java.lang.Integer.
    >
    request.setAttribute("sampleVar",sample );// you must put that in the response, not in the request...
    response.setAttribute("sampleVar",sample );This is not right. You have to set the attribute in request object as you are getting the attribute back in jsp from the request object.
    855548 wrote:
    Hi!! thanks for answering the question,,
    i have tried doing as u said , but still m getting the following error:
    On Compilation of JSP.
    cannot resolve symbol
    symbol : method parseInt (java.lang.Object)
    location: class java.lang.Integer
    int numberofcols = Integer.parseInt(request.getAttribute("noOfCols"));
    kindly help.request.getAttribute("noOfCols") gives you an object of java.lang.Object. Integer.parseInt(String str) requires a string.
    do this....
    int numberofcols = Integer.parseInt(request.getAttribute("noOfCols").toString());

  • Passing values from javascript in pop up window to parent jsp

    Hi
    I am trying to pass values from a pop up window to the main window that popped this child window , with the idea to have the parent window refresh itself with value from pop up window.But the values are not going through.I do a request on the hidden variable but when the parent
    jsp refreshes , the variable is still null...
    The following is the code i have .
    Parent jsp:a.jsp
    <form name='summary'>
    <input type=hidden name=customerid value="">
    <input type="button" class="textButton" name="action" value="customerlist" onClick="javascript:openWin('b.jsp','800','350')">
    <script>
    function openWin(loc, w, h) {
    var newWin = window.openloc,"HTML",'dependent=1,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=' + w + ',height=' + h);
    newWin.window.focus();
    </SCRIPT>
    <%
    String optionVal = request.getParameter("customerid");%>
    var user = "<%= optionVal%>";
    </form>
    child jsp- b.jsp (pop up window)
    <script>
    function closer(){
    var val = document.formname.id.selected.value;
    window.opener.document.summary.customerid.value = val;
    window.opener.location.reload();
    </script>
    <form name = formname>
    <input type="text" name="id" value = ''>
    <input type="button" class="textButton" value="select"
    onClick="closer();window.close();">
    </form>
    Any ideas on what i am missing
    Thanks
    Arn

    use window.opener.document.forms[0].filedname.value = 'value u need to set'

  • Passing values  between action classes.

    there are 2 jsps. main.jsp and detail.jsp In Main. jsp i only enter project description and submit to database and map the struts to call the detail .jsp which has to pick the project id(which is sequence generator) and display its description so I can add the other details of project.
    Now the problem is as I submit the aciton the request goes out of scope and I am unable to get the project Id so I can't find the project desc to display in my details page.
    i tried populating the form before I leave the save action which is called in first jsp. But I am still not able to get the value of project id. Below is my code
    ProjectDetailForm form = (ProjectDetailForm) aform;
    ......save action is done...
    form.setProjectId(projectNumber);
    to make it clear project number is the number i wast assing to projectid and its sequence generator in datamap.
    In display action where I want value so i can dispaly the project desc in Detail.jsp
    ProjectDetailForm form= (ProjectDetailForm) aForm;
    int projectNumber=form.getProjectId();
    Please anybody let me where I am going wrong. Its kind of urgent.
    Regards,
    Infyniti.
    One wya is querystring, which not preferred in our proj. Is there any susbstitution for querystring in struts.
    Its kin of urgent.

    I'm not entirely certain what you are doing, but heres a best guess:
    If I understand you correctly you want to chain two actions
    1 - save action - saves new record, and generates new unique id
    2 - display action - displays the new record.
    Seeing as you say "the request goes out of scope", I presume that means that your actionForward to go from the save action to the display action is a redirect?
    Pro: a refresh won't save a duplicate new record
    Con: you lose all request attributes/parameters.
    So one request saves the record, and the redirect causes a new request to display the record. But you need to retain the record id between the two requests.
    Setting it on the ActionForm should work providing:
    - the same ProjectDetailForm used in both the "save" action and the "display" action?
    - the form have a scope of "session"
    - you don't have a "reset" method that would clear the value between calls
    Are you able to post the struts-config for these two actions?
    Given the constraints, the only other alternative I can think of is to put the id in a session attribute.
    As an alternative, you could make it so that the save action forwards to display without a redirect, but that opens you up to a "refresh" saving a new record again. You could combat that by using struts synchronizer tokens. http://www.javaworld.com/javaworld/javatips/jw-javatip136.html
    Hope this helps,
    evnafets

  • Passing Variables from One Class to Another

    Hello, I am new to Java Programming and I'm currently starting off by trying to build a simple application.
    I need help to pass variables created in one class to another.
    In my source package, I created 2 java classes.
    1. Main.java
    2. InputFileDeclared.java
    InputFileDeclared reads numerical data from an external text file and store them as string variables within the main method while Main converts a text string into a number.
    Hence, I would like to pass these strings variables from the InputFileDeclared class to the Main class so that they can be converted into numbers.
    I hope somebody out there may enlighten me on this.
    Thank you very much in advance!

    Values are passed from method to method, rather than from class to class. In a case such as you describe the code of a method in Main will probably call a method in InputFileDeclared which will return the String you want. The method in Main stores that in a local variable and processes it. It really doesn't matter here which class the method is in.
    You InputFileDeclared object probably contains "state" information in its fields such as the details of the file it's reading and how far it's got, but generally the calling method in Main won't need to know about this state, just the last data read.
    So the sequence in the method in Main will be:
    1) Create an new instance of InputFileDeclared, probably passing it the file path etc..
    2) Repeatedly call a method on that instance to return data values, until the method signals that it's reached the end of file, e.g. by returning a null String.
    3) Probably call a "close()" method on the instance, which you should have written to close the file.

  • Pass RowSet from one class to another

    Hi, i am trying to pass a rowset from one class to another but i keep getting the error messages:
    method does not return a value
    statement not reachable
    Does anybody know why?
    package project1;
    import java.sql.SQLException;
    public class readdata {
        public static void main(String[] args) {
            Class2 cl = new Class2();
            try {
            while (cl.openConnection().next()) {
                System.out.println(cl.openConnection().getInt("id") + "-");
            catch (SQLException se)
                    System.out.println(se);
           // while (rs.next())
             //       System.out.println(rs.getInt("id") + "-");
             //       System.out.println(rs.getString("field1") + '\n');
    package project1;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    import javax.sql.RowSet;
    public class Class2 {
       private Connection conn;
        public Class2() {
            openConnection();
        public RowSet openConnection()
                try
                        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
                        conn = DriverManager.getConnection("jdbc:odbc:;DRIVER=Microsoft Access Driver (*.mdb);DBQ=D:\\test.mdb;PWD=","admin","");
                        Statement command = conn.createStatement();
                        RowSet rs = (RowSet)command.executeQuery("select * FROM testing");
                        return rs;
                        System.out.println("Connected To Access");
                        rs.close();
                        conn.close();
                catch (SQLException se)
                        System.out.println(se);
                catch (Exception ex)
                        System.out.println(ex);
    }Thanks in advance
    Message was edited by:
    snipered2003
    Message was edited by:
    snipered2003

    Hi snipered2003
    I'm fairly new to java, so check out anything I say.
    to me it appears that the code within your try block in the main method of readdata class can never throw a SQLException since the calls are to cl.openConnection() which catches any SQLException and does not throw it.
    So one statement not reachable is the statement in the catch blockSystem.out.println(se);Second, the only return statement in your openConnection() method is inside the try block, whic means that if an exception is encountered there will be no RowSet returned by the method.
    Secondly, the code in the try block in your Class2.openConnection() after the return statement will also never be reached.
    You may need something like    public RowSet openConnection()
            RowSet rs = null;
            try
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
                conn = DriverManager.getConnection("jdbc:odbc:;DRIVER=Microsoft Access Driver (*.mdb);DBQ=D:\\test.mdb;PWD=","admin","");
                Statement command = conn.createStatement();
                rs = (RowSet)command.executeQuery("select * FROM testing");
                System.out.println("Connected To Access");
            catch (SQLException se)
                System.out.println(se);
            catch (Exception ex)
                System.out.println(ex);
            return rs;
        }But you will have to check for a null return value in the call to the method.
    It also looks like the code in your main method, when these things are ironed out, will run an infinite loop, but I could be wrong on that.
    I think (note: think) this part should be        RowSet rs = cl.openConnection()
            if (rs != null) {
                while (rs.next()) {
                    System.out.println(rs.getInt("id") + "-");
                rs.close();
            }Anybody please correct me if I am wrong.
    And I don't know where the conn.close would fit in this scheme of things.
    Cheers, Darryl

  • How update xellerate form data from Action class

    Hi Experts,
    i did some customization in Action class.
    Now from this Action class i want toupdate xellerate from data
    Using digital signature i got the status of one of the attribute of xellerate from
    ie
    userIntf = (tcUserOperationsIntf)utilityFactory.getUtility("Thor.API.Operations.tcUserOperationsIntf");
    tcResultSet tRs = userIntf.findAllUsers(userMap);
    if(tRs.getRowCount() > 0)
    userLoginStatus= tRs.getBooleanValue("USR_UDF_IS_FIRST_LOGON");
    now i want update this attribute, ie ifuserLoginStatus is true, i want to update as false
    help me how to achive this..
    thanks

    How to update userdata using OIM API
    Thanks

  • Basic jsp and servlet question (JSP Model 2)

    Hi
    I want to make an website where i use JSP Model 2 architecture. However I got a basic question
    1. I need to separate business logic from presentation with the use of jsp and servlets. Meaning I want no html code in the servlet. Can you give a simple example of how this can be done? If I map my implementation of httpServlet to a jsp page in web.xml and override doPost() and doGet(). The calls to the jsp page comes to the servlet as it should. I want to process some methods (calling sessionbeans or similar which in turn calls entitybeans) and then show the jsp page.
    How do I show the jsp page without mixing html in the servlet as I've done below:
    doGet(HttpServletRequest req, HttpServletResponse res)
    PrintWriter p = response.getWriter();
    p.print("<html><body>Hello world</body></html>"); //I dont want to do //this, I want to display the JSP site
    doPost(HttpServletRequest req, HttpServletResponse res)
    //doSomething
    }Message was edited by:
    CbbLe

    You should treat your servlet class much like a controller, where you can then use JSP as the view. The way you achieve this is to use the forward() method in RequestDispatcher.
    Say you've got a servlet class org.yoursite.controller.YourController:
    public void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
      //Set some value for use in the JSP file associated wth me
      req.setAttribute("greeting", "Hello world!");
      //Done with our business logic, off we go to the JSP file
      ServletContext app = getServletContext();
        RequestDispatcher disp;
        disp = app.getRequestDispatcher("/some/jsp/file.jsp);
        disp.forward(req, resp);
    }Now in your JSP file:
    <h1>Example</h1>
    <div>
      I just want to say <%= request.getAttribute("greeting") %>
    </div>Going to that servlet now executes business logic and then points to the JSP file for the view. You can forward from servlet to servlet too if needs be. The string you pass to forward() is whatever would be in the URI of the request so any <servlet-mapping> configurations in web.xml are used ;)
    There is some pretty in-depth documentation on the J2EE blueprints website, namely service-to-worker and front-controller patterns. I dare say if you're looking for this sort of code you'll want to look at the composite view pattern too (also on blueprints).

  • How to pass string from a class to another on button click

    Hai forum i'm developing an application in which i have frame1(seperate class without main) where i get a excel files and get the tablenames of it(sheets).
    There i choose a sheet from availabe sheets and i have to pass it frame2 on clicking a button on frame1.
    The sheet name is chosen from a JComboBox in frame1:(code)
    sheetcombo.addActionListener(new java.awt.event.ActionListener()     
                        public void actionPerformed(java.awt.event.ActionEvent e)
                                  JComboBox cb = (JComboBox)e.getSource();
                                  String sheetname = (String)cb.getSelectedItem();
    I dont get how to pass this String sheetname to frame2 where i call the constructor of frame1 initialize it. Help me out. Thanks in advance...

    1 write a set method in frame 2 class
    2 create a instance of frame 2 class in frame 1
    3 in actionaPerformed method write code as follows
    frame2obj.set(sheetname)
    this should work :-)

  • Passing Params from Mutiple Class in a Single Script

    Hi Folks,
    there is a scenario where there are many parameters (optional and mandatory parameters) , which are to be used across different functions with in a child script called CHDS
    So I want to create a separate class ABC with in the same script and declare all those parameters in it and then pass the entire class as an argument to a function.
    Then I would declare an instance ABC and access those parameters required for that particular function.
    so The first class in the script is by defaut
    public class script extends IteratingVUserScript {
    public void functionA1(ABCparams) throws Exception
    ABCparams abc = new ABCparams();
    app.field1 = abc.parameter1;
    app.field2 = abc.parameter2;
    app.field6 = abc.parameter6;
    app.field7 = abc.parameter7;
    public void functionB2(ABCparams) throws Exception
    ABCparams pqr = new ABCparams();
    app.field3 = pqr.parameter3;
    app.field4 = pqr.parameter4;
    app.field8= pqr.parameter8;
    app.field9 = pqr.parameter9;
    Now the second class is
    public class ABCparams
    parameter1;
    parameter2;
    parameter3;
    parameter4;
    parameter5;
    parameter6;
    parameter7;
    parameter8;
    parameter9;
    parameter10;
    parameter11;
    parameter12;
    However the values for parameters declared in class ABCparams would be read from a databank of a parent script PRNS, i.e parent PRNS would invoke child script CHDS.
    Do you think that, this a feasible approach?

    Im not sure whether you can store the internal table into Java script array.
    Look at the below thread, it may help you
    pass an internal table to a javascript function
    By the way you want to store the itab into javascript?
    Raja T
    Message was edited by:
            Raja Thangamani

  • Retrieve data  from entity bean to struts and display in JSP

    I am integrating Struts+EJB3.0.
    Now i need to retrieve data stored in mysql database through entity bean to struts framework*(Action Form*).Then i need to display it in JSP page.(display using combo box).
    Please Any one give suggestions!!!!!
    Thanks in advance

    I got the solution.
    --Jagan.+                                                                                                                                                                                                                               

Maybe you are looking for

  • Sample application from OTN - not able to run

    I have downloaded "Master-Detail-MoreDetail Sample Application" sample from OTN, but it fails to run and gives the error below. any ideas are appreciated. *** Using port 7101 *** "C:\Documents and Settings\sgodavar\Application Data\JDeveloper\system1

  • How to create a proper ePub Zip file on the Mac

    I need to zip my iBook content with two critical requirements: 1) the first file must be the "mimetype" file (my ZipIt utility wants to reorder files, alpha, by name, rather than retaining the order that files are added into the archive). 2) that fir

  • Importing Home Folder after new hard drive and Lion Update

    (Okay, long title.) Had to replace my hard drive. Was running Tiger.  Backed up my entire Home Folder only, on an external harddrive, before it failed completely. Hard drive replaced, and then loaded Snow Leopard, updated to latest version, 10.6.8. R

  • My ipad says the ios needs seven hours to update. I tried the reboot but no success help!

    THe ios is very slow and says seven hours help me

  • GR for PO in wm

    hi, in general when  you put goods receipt for  purachse order for warehouse maintain material it will move to the source bin as purchase order number in interim storage area. when you confirm the TO it will move to the destination bin as configured