Hi, I am new to struts2.
I am trying to fetch data in
jsp page but can not see anything.
In my action class, I am fetching user_id and passwd from jsp page then from that I am fetching person's personal information and agency's information in which that person is admin.
my action class is
package com.dhaval.view;
import java.util.Iterator;
import java.util.List;
import com.dhaval.controller.AgencyManager;
import com.dhaval.controller.LoginManager;
import com.dhaval.model.LoginModel;
import com.dhaval.controller.PersonManager;
import com.dhaval.model.PersonModel;
import com.dhaval.model.AgencyModel;
import com.opensymphony.xwork2.ActionSupport;
public class PersonAction extends ActionSupport {
private static final long serialVersionUID = 9149826260758390091L;
private PersonModel person;
private List<PersonModel> personList;
private AgencyModel agency;
private List<AgencyModel> agencyList;
private
String Person_Name;
private String Person_Passwd;
private PersonManager linkController;
private LoginManager loginController;
private AgencyManager agencyController;
public PersonAction() {
linkController = new PersonManager();
loginController = new LoginManager();
agencyController = new AgencyManager();
}
public String execute() {
String name = getPerson_Name();
String passwd = getPerson_Passwd();
int ID = loginController.list(name,passwd);
personList = linkController.list(ID);
Iterator iter = personList.iterator();
while (iter.hasNext()) {
person = (PersonModel) iter.next();
System.out.println("Hope: "+person.getPerson_Name());
System.out.println(person.getPerson_Role());
}
agencyList = agencyController.list(ID);
Iterator iter1 = agencyList.iterator();
while (iter1.hasNext()) {
agency = (AgencyModel) iter1.next();
System.out.println(agency.getAgency_ID());
System.out.println("Hope: "+agency.getAgency_Name());
System.out.println("Hope: "+agency.getAgency_Description());
System.out.println("Hope: "+agency.getAgency_Address1());
System.out.println("Hope: "+agency.getAgency_Address2());
System.out.println("Hope: "+agency.getAgency_City());
System.out.println("Hope: "+agency.getAgency_State());
System.out.println(agency.getAgency_Zipcode());
System.out.println("Hope: "+agency.getAgency_Email());
System.out.println("Hope: "+agency.getAgency_Phone());
}
return SUCCESS;
}
private String getPerson_Passwd() {
// TODO Auto-generated method stub
return Person_Passwd;
}
public PersonModel getperson() {
return person;
}
public List<PersonModel> getpersonList() {
return personList;
}
public void setperson(PersonModel person) {
this.person = person;
}
public void setpersonList(List<PersonModel> personList) {
this.personList = personList;
}
public AgencyModel getagency() {
return agency;
}
public List<AgencyModel> getagencyList() {
return agencyList;
}
public void setagency(AgencyModel agency) {
this.agency = agency;
}
public void setagencyList(List<AgencyModel> agencyList) {
this.agencyList = agencyList;
}
public String getPerson_Name() {
return Person_Name;
}
public void setPerson_Name(String Person_Name) {
this.Person_Name = Person_Name;
}
public void setPerson_Passwd(String Person_Passwd) {
this.Person_Passwd = Person_Passwd;
}
}
In this class, I am able to see information through iterator in console. but i dont know, its not coming in jsp page as such I do have get and set methods of list
my jsp page is
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<title>
Struts 2 - Login Application | By Dhaval Tamboli</title>
</head>
<body>
<h2>Howdy, <s:property value="Person_Name" />...!you are awesome</h2>
<table>
<tr>your information</tr>
<tr>
<th>ID</th>
<th>Role</th>
</tr>
<s:iterator value="agencyList" status="rowstatus">
<tr>
<td><s:property value="Agency_Name" /></td>
<td><s:property value="Agency_City"/></td>
</tr>
</s:iterator>
</table>
</body>
</html>
here, AgencyList is list of AgencyModel , which has fields of Agency_Name, etc. and there also I put get and set methods.
here's my struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="false" />
<constant name="struts.custom.i18n.resources" value="ApplicationResources" />
<package name="default" extends="struts-default" namespace="/">
<action name="getLogin" class="com.dhaval.view.LoginAction">
<result name="success">Welcome.jsp</result>
</action>
<action name="getPerson" class="com.dhaval.view.PersonAction">
<result name="success">dhaval.jsp</result>
</action>
</package>
</struts>
in index.jsp
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<title>Struts 2 - Login Application | By Dhaval Tamboli</title>
</head>
<body>
<h2>Struts 2 - Login Application</h2>
<s:actionerror />
<s:form action="getPerson" method="post">
<s:textfield name="Person_Name" key="label.username" size="20" />
<s:textfield name="Person_Passwd" key="label.password" size="20" />
<s:submit method="execute" key="label.login" align="center" />
</s:form>
</body>
</html>
Let me know, if I am not clear. I can see value of person_name but not value of that list.
Thanks in advance,
dhaval