Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Struts How to pass Array of string from action class to jsp page
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


gopi
How to pass Array of string from action class to jsp page
1 Answer(s)      2 years and a month ago
Posted in : Struts


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


Advertisement
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 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 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 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 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 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 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
[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
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
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
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 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 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 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 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
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
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 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 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... class B { static int b=A.get(); public static void main(String[]args
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
Advertisements
 

 

 

DMCA.com