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