How to pass Array of string from action class to jsp page

Ads
 

How to pass Array of string from action class to jsp page

this is my action class

package login.ipm;

import java.sql.*; import java.util.ArrayList; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping;

/** * * @author Gopi Daggumalle */ public class DiagservicesAction extends org.apache.struts.action.Action {

private static final String SUCCESS = "success";

@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response)
        throws Exception 
{
    int count=0;
Connection con=null;
ResultSet rs;
Statement st;
    HttpSession session=request.getSession(true);
    DiagservicesForm lf=(DiagservicesForm) form;
    String pname=lf.getPname();
    String ref=lf.getRef();
    String tno=lf.getTno();
    String cbox=lf.getCbox();
    int age=lf.getAge();
    String sex=lf.getSex();
    String cost=lf.getCost();
    String counter=lf.getCounter();
    String vno=lf.getVno();
    String amt=lf.getAmt();
    String[] check =request.getParameterValues("cbox");
    int a=check.length;
    //request.setAttribute("check", a);


    String testname[]=new String[200];
String testcode[]=new String[200];
String dept[]=new String[200];
String cost1[]=new String[200];
String counter1[]=new String[200];

   /* if (check != null)

{ for (int i = 0; i < check.length; i++) { System.out.println (check[i]); } } else System.out.println ("none"); */ try { ArrayList UserList1=new ArrayList(); for(int i=0;i

        st = con.createStatement();
        rs = st.executeQuery("SELECT * FROM user_charges WHERE TEST_CODE="+tcode+" and service_code=1");
        //System.out.println("SELECT * FROM user_charges WHERE TEST_CODE="+tcode);
        while (rs.next())
        {
            dept[count] = rs.getString("department");
            testcode[count] = rs.getString("test_code");
            testname[count] = rs.getString("test_name");
            count++;

        }
    }

    }
    catch(Exception exception)
    {
        System.out.println(exception);
    }

    for (int i = 0; i < check.length; i++) 
  {
    System.out.println (testname[i]);
  }



    request.setAttribute("testname", testname);



    ArrayList print=new ArrayList();


     PrintDiagForm cf=new  PrintDiagForm();
     cf.setPname(pname);
     cf.setRef(ref);
     cf.setTno(tno);
     cf.setAge(age);
     cf.setSex(sex);
     cf.setCost(cost);
     cf.setCounter(counter);
     cf.setVno(vno);
     cf.setCbox(cbox);
     cf.setAmt(amt);




     print.add(cf);
     session.setAttribute("print",print);

    return mapping.findForward(SUCCESS);
}

}

my jsp page is

<%-- Document : select_service Created on : Aug 31, 2012, 11:59:00 PM Author : Gopi Daggumalle --%>

<%@page contentType="text/html"%> <%@page pageEncoding="UTF-8"%>

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %> <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %> <%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>

Institute of Preventive Medicine

<body OnLoad='javascript:print()'> <center><b>INSTITUTE OF PREVENTIVE MEDICINE P.H.LABS & FOOD(H) ADMINISTRATION ,<br> CENTRAL RECEPTION SECTION , Narayanaguda , Hyderabad - 500029 A.P </B><BR><B>MASTER SLIP</B></CENTER><BR>
   <table>
<logic:iterate  name="print" id="print"  indexId="i">
     <tr>
        <td>Patient Name</td><td><bean:write name="print" property="pname"/></td>
    </tr>
        <tr>
        <td>Reference Bye</td><td><bean:write name="print" property="ref"/></td>
    </tr>
        <tr>
        <td>Token Number</td><td><bean:write name="print" property="tno"/></td>
    </tr>
        <tr>
        <td>age</td><td><bean:write name="print" property="age"/></td>
    </tr>
        <tr>
        <td>Sex</td><td><bean:write name="print" property="sex"/></td>
    </tr>
        <tr>
        <td>Cost</td><td><bean:write name="print" property="cost"/></td>
    </tr>
        <tr>
        <td>Counter Number</td><td><bean:write name="print" property="counter"/></td>
    </tr>
        <tr>
        <td>Visit no</td><td><bean:write name="print" property="vno"/></td>
    </tr>
        <tr>
        <td>Test Name</td><td></td>
    </tr>
        <tr>
        <td>Total Amount</td><td><bean:write name="print" property="amt"/></td>
    </tr>

</logic:iterate>


</table>

<% String[] str = (String[])request.getAttribute("testname"); out.println("name"+str); %>

pls reply

View Answers

September 10, 2012 at 5:24 PM

You can use session.setAttribute() and session.getAttribute() methods. In your action class,

String[] arr = {"A","B","C","D"};
for (int x = 0; x < arr .length; x++) {
out.println(arr[x]);
}
session.setAttribute("names", arr);

And through your jsp page, get array values.

<%
try {

String[] str = (String[]) session.getAttribute("names");

for (int x = 0; x < str.length; x++) {
out.println(str[x]);
}

} catch (Exception e) {
out.println(e);
}
%>

Ads









Related Tutorials/Questions & Answers:
How to pass Array of string from action class to jsp page
How to pass Array of string from action class to jsp page  this is my action class package login.ipm; import java.sql.*; import java.util.ArrayList... jsp page is <%-- Document : select_service Created on : Aug 31
how to pass string array from action class to jsp page? pls reply me.
how to pass string array from action class to jsp page? pls reply me.  how to pass string array from action class to jsp page? pls reply me.  ...); And through your jsp page, get array values. <% try { String[] str = (String
Advertisements
How can i pass the valus from a JSP to the action class???
How can i pass the valus from a JSP to the action class???  hewllo wevryone... can anyone help me with how i can pass the value of menuId in my JSP and pass it in the action class
how to pass a string from one class to another
how to pass a string from one class to another  hi all, Good morning. I am trying to develop a coding pass a string from one class and declare in other class. the string which i need to pass is the data from an file and i want
Pass value of rasio button from jsp page to action class(not conventional problem)
Pass value of rasio button from jsp page to action class(not conventional problem)  Hi, I have a jsp page that has code which goes ike this: <... in action class using getter setter and hence corresponding data can be deleted. i
how to pass variable from simple java main class(not servlet) to the jsp page?
how to pass variable from simple java main class(not servlet) to the jsp page?  I have a simple Java class in which I invoke a call to a JSP page... from the simple Java class to the JSP page. How can I do that? Here is my
How to pass the value from controller to jsp page ?
How to pass the value from controller to jsp page ?  HI I need to pass the value from controller to jsp. I use the way like this Controller request.setAttribute("msg", "Successfully Login"); In jsp ${msg} and then i
How to pass an arraylist from servlet to jsp?
How to pass an arraylist from servlet to jsp?  Hello, Can anyone please tell me how to pass an arraylist from servlet to jsp? I have two arraylist one of type String and the other int. How to send both the arraylists from
How to pass multiple values from a servlet to JSP?
How to pass multiple values from a servlet to JSP?  hi, I want to pass multiple values form a servlet to JSP. Hw do i do that? I am able to send one value at a time without any prb, but I am unable to carry multiple (from two
[JSP] How to pass back ID to previous page.
[JSP] How to pass back ID to previous page.  Hi experts, May I ask something. How to link a page to previous page which the content in previous page is selected from database where IDPRODUCT=". I don't know how to pass back
how to display output on jsp from while loop of action class....actually i am retreiving the post from posts column from my sql.plz help.thnkss
how to display output on jsp from while loop of action class....actually i am retreiving the post from posts column from my sql.plz help.thnkss  how to display output on jsp from while loop of action class....actually i am
How to validate a form in action class and forward errors to the jsp in struts?
How to validate a form in action class and forward errors to the jsp in struts?  How to validate a form in action class and forward errors to the jsp in struts
How to pass variable from one class to another in java
How to pass variable from one class to another in java  How to pass variable from one class to another in java?   Example: public class...; } } //Another class Class2. public class Class2 { public static void main(String
how to pass values from 2nd page tp 3rd page....
how to pass values from 2nd page tp 3rd page....  Hi, How to pass values from 2nd page to 3rd page..... here are my programs(not exactly correct... method="post" action="details.jsp"> String uid=request.getParameter("userid
RADIO FROM JSP TO ACTION.
RADIO FROM JSP TO ACTION.  Hi frds, how to get the selected multiple radio button values from jsp to action
How to close a frame on action event of a button from a different class ?
How to close a frame on action event of a button from a different class ?  How to close a frame on action event of a button from a different class ? I have a designed a control-frame on 1 class which has jbutton components, I
how to access JQuery array in jsp page?
how to access JQuery array in jsp page?  JQury Array: var elems =this.value; var arr = jQuery.makeArray(elems); How to get in jsp page
how to give link from jsp to jsp page
how to give link from jsp to jsp page  hi this is my following code...,password); String query = "select * from employee"; st = con.createStatement... language="java"%> <%@page import="java.sql.*"%> <form method="post" action
how to give link from jsp to jsp page
how to give link from jsp to jsp page  hi this is my following code...,password); String query = "select * from employee"; st = con.createStatement... language="java"%> <%@page import="java.sql.*"%> <form method="post" action
How to retrieve array values from html form to jsp?
How to retrieve array values from html form to jsp?  Hi! I am... sample code for how to retrive array values from html to jsp.   hi friend... it into jsp. Means i just want to retrieve values from html form containing array
Struts2.2.1 Action Tag Example
class directly from a JSP page. We can call action directly by specifying... the results from the Action. The following Example will shows how to implement the Action tag in the Struts2.2.1 -- First we create a JSP file named
Pass a dom object from jsp to servlet
Pass a dom object from jsp to servlet  I am creating a dom object in my jsp page. now i want to pass that object in a servlet through calling servlet in jsp. can anyone help me
How to read and display data from a .properties file from a jsp page
How to read and display data from a .properties file from a jsp page  I have a .properties file. I have to create a jsp page such that it reads... = DEDCHGG_PWDP and goes on... I have to create a jsp page to show these data
Calling a jsp page from Servlet
Calling a jsp page from Servlet  How can I do this? Suppose I have jsp page aaa.jsp. From aaa.jsp on form action I have made a call to a servlet... List and data is being retrieve. Now I want to pass this List to another jsp page
How to pass javascript variable in Scriplet of JSP?
How to pass javascript variable in Scriplet of JSP?  How can I assign the value of a javascript variable to a variable declared in jsp scriplet? Is it possible
How to Get The Data from Excel sheet into out jsp page???
How to Get The Data from Excel sheet into out jsp page???  How to Get The Data from excel sheet to out jsp page in webApp
Pass value from JSP to JavaScript
Pass value from JSP to JavaScript       We can also pass the value from a JSP page to the java... script from the HTML page. Since in JSP page we can embed HTML tags as well. 
How save,get picture from database in my jsp page?
How save,get picture from database in my jsp page?  How i save picture in db after browsing it,and also how i get it on my other jsp page
how to insert the bulk data into the data base from the table of jsp page to another jsp page
how to insert the bulk data into the data base from the table of jsp page to another jsp page  pls help i'm doing the project called centralized... to get values in array in next jsp page and insert into the row by row Please do
How we delete a data of database from front end jsp page
How we delete a data of database from front end jsp page   I make a website and featch a data from data base and now i want that a delete button put... deleted from jsp page as well as from database.I used mysql and jsp. Please help me
how to display image and text in single jsp page from the mysql database
how to display image and text in single jsp page from the mysql database  hello please help me to display the image and text in single jsp page from mysql database if have any reference code please send me Thanks in advance

Ads