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:
Advertisements
how to pass a string from one class to anotherhow 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 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 input from radio button to jsp pagehow 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 pagehow 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 pagehow 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 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 ServletPass 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 pass variable from one class to another in javaHow 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 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
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 give link from jsp to jsp pagehow 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 pagehow 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 servletPass 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-ServletJSP 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 classhow 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 how to convert jsp page to class file - JSP-Servlethow 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 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
Calling a jsp page from ServletCalling 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 TagStruts 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
Select string from array in objective cSelect
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