File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes problem getting list in jsp page in struts2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "problem getting list in jsp page in struts2" Watch "problem getting list in jsp page in struts2" New topic

problem getting list in jsp page in struts2

dhaval tamboli

Joined: Aug 02, 2010
Posts: 25
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);

System.out.println("Hope: "+person.getPerson_Name());

agencyList = agencyController.list(ID);
Iterator iter1 = agencyList.iterator();
while (iter1.hasNext()) {
agency = (AgencyModel);
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("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) { = 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"%>
<title>Struts 2 - Login Application | By Dhaval Tamboli</title>

<h2>Howdy, <s:property value="Person_Name" />...!you are awesome</h2>

<tr>your information</tr>

<s:iterator value="agencyList" status="rowstatus">

<td><s:property value="Agency_Name" /></td>
<td><s:property value="Agency_City"/></td>



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" ?>
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
<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 name="getPerson" class="com.dhaval.view.PersonAction">
<result name="success">dhaval.jsp</result>

in index.jsp

<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<title>Struts 2 - Login Application | By Dhaval Tamboli</title>

<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" />

Let me know, if I am not clear. I can see value of person_name but not value of that list.

Thanks in advance,
Ankit Garg

Joined: Aug 03, 2008
Posts: 9462

Hi dhaval, welcome to javaranch.

Dhaval please Use Code Tags when you post a source code. That way your code looks formatted. Unformatted code is hard to read. You can add code tags by wrapping your code in [code] [/code] tags. You can edit your message using button and then add code tags to it...

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Richard Golebiowski
Ranch Hand

Joined: May 05, 2010
Posts: 213

Your getter should be getAgencyList(), not getagencyList()
dhaval tamboli

Joined: Aug 02, 2010
Posts: 25
Thanks to both of you but I just figured it out , my problem was with access. I just need to give public access to Agencylist instead of its working fine.
again thanks
David Newton

Joined: Sep 29, 2008
Posts: 12617

No, you should change the list getter method to be the proper name, not just expose your internal properties.

Also, your variable naming conventions are quite un-Java-like: there's no *technical* reason to follow Java conventions, but if you want people to be able to read your code most efficiently, it's a good idea to follow the guidelines.
dhaval tamboli

Joined: Aug 02, 2010
Posts: 25
hey thanks.. You were right.. i should not use public.. with getAgencyList() its working fine.. and next time I will keep in mind regarding coding standards ..

I agree. Here's the link:
subject: problem getting list in jsp page in struts2
It's not a secret anymore!