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; 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);
}
%>









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
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 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
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 an array from one jsp to another jsp - JSP-Servlet
how to pass an array from one jsp to another jsp  hi friedns, can any One tell me how to send an array from one jsp to another jsp,pls any one send the code for this.also porvid the code how to retrive the arry in another jsp
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 parametes from JSP page to HTML page? - JSP-Servlet
How to pass parametes from JSP page to HTML page?  Hi all, In my project I have one JSP page and one HTML page. In JSP page I have created HTML... to pass the values from my JSP page to HTML page. Pls help me out. Hitendra 
how to pass form values from javascript of html page to jsp page
how to pass form values from javascript of html page to jsp page   This is my sample html page which contains inline javascript which calculates... showlocation funtion to submitform.jsp page and display latitude value in jsp page
how to pass input from radio button to jsp page
how to pass input from radio button to jsp page  hi.. the code below here there are list of radio buttons here in jsp page when the values are matched from database. I want to pass the selected value in Struts Action FormBean
how to pass input from radio button to jsp page
how to pass input from radio button to jsp page  hi.. the code below here there are list of radio buttons here in jsp page when the values are matched from database. I want to pass the selected value in Struts Action FormBean
how to pass input from radio button to jsp page
how to pass input from radio button to jsp page  hi.. the code below here there are list of radio buttons here in jsp page when the values are matched from database. I want to pass the selected value in Struts Action FormBean
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 forward select query result to jsp page using struts action class
how to forward select query result to jsp page using struts action class  how to forward select query result to jsp page using struts action class
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
Pass parameters from JSP to Servlet
Pass parameters from JSP to Servlet In this section, you will learn how to pass parameters from JSP page to servlet. For this purpose, we have used...: <%@page language="java"%> <% request.setAttribute("Company
[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 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
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 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 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
how can we pass parameters from jsp href to another servlet
how can we pass parameters from jsp href to another servlet  how can we pass parameters from jsp href to another servlet
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
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
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 pass the mutiple values from <Ui:datagrid hyperlink - JSP-Servlet
how to pass the mutiple values from    I am getting the error when passing the values from this way emp2=${employee.lastName1} & name=${employee.firstName.How to pass the values from hyperlink in column
how to pass the mutiple values from <Ui:datagrid hyperlink - JSP-Servlet
how to pass the mutiple values from      Hi Friend, Please post your full code. Thanks
how to pass arraylist data from one jsp to another jsp - JSP-Servlet
how to pass arraylist data from one jsp to another jsp  hi to all iam... to receive all employee id's that are retrived from the database in the first jsp... the following >XXX/ ? is required to send a value from one jsp to another
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
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
JSP to output Java String Array - JSP-Servlet
JSP to output Java String Array  I am just a little confused about the output that I would get from printing a 2D String array loaded with database fields. For example lets say we have the following array: String [ ][ ] array
how to pass class variable to another class
how to pass class variable to another class  i need to access a variable from a class to another class currently running at the same time. using..._TO_REPLACE_1 Try the following code: import java.util.*; class A { static int regd
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
create a string from an array using JavaScript
create a string from an array using JavaScript  How to use "join()" to create a string from an array using JavaScript
how to convert jsp page to class file - JSP-Servlet
how to convert jsp page to class file  hai. iam doing online banking project by using jsp.i completed all the jsp pages.next can you tell me how to convert these jsp pages to class files with example and where to copy these class
How to pass value from dijit.Tree to dijit.MenuItem - Ajax
How to pass value from dijit.Tree to dijit.MenuItem  Hi Friends, I have generated a tree structure in a jsp along with context menu besides each... side(Struts action class) I have passed a JSON structure through URL
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. 
Convert String to Class - JSP-Servlet
. Reading job name, class name, day & time using xml file only. Problem is while reading class name, retrieve as a string format but Quartz required in "Class" format...Convert String to Class  Hi all, I am using Quartz as a scheduler
String Class in Action Script3
.style1 { font-size: medium; } String Class in Action Script3:- String class is a data type. String class provides methods for access... types of String class objects. String class have different types of constructors
Understanding Struts Action Class
Class and forward a jsp file through it.  What is Action Class?ADS... in this page). Here is code of our Action Class:ADS_TO_REPLACE_3... on the user browser. In this lesson you learned how to create Action Class and add
how to store the data in a array retrived from the database - JSP-Servlet
how to store the data in a array retrived from the database  hi... in database,and i need to disply all the employees record in a single jsp. pls can any one tell me how to do it this using jsp. thankyou,  Hi nagaraj
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
Struts 2 Action Tag
Struts 2 Action Tag "action" Tag in Struts 2 is used by developer to call action class from a JSP page. For calling the action class, developer must assign action name. Struts 2 Action Tag is one of the Data Tags, which are used
Parameter passing from jsp page to jsp page - JSP-Servlet
Parameter passing from jsp page to jsp page  Hi I intends to pass the parameters that I received from previous page through query String. I get all parameter in respective string variables. I have to passed the parameters
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
Sending error code to access log of tomcat server from Action class
Sending error code to access log of tomcat server from Action class  How to send an error code (500) to access log file when we get null value in an if condition in Action class? Is anyone aware of this! Thanks
Select string from array in objective c
Select string from array in objective c  Hi, I wanted to select a string from the database table in objective c. But somehow it is not working..can...:@"SELECT ic, district, age, race, referralSource, DMRelatedAdmin, postalCode FROM

Ads