This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java and have Dr. Raoul-Gabriel Urma & Richard Warburton on-line!
See this thread for details.
Win a flower (🌹) or copy of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java (📚) this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
master stewards:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
garden masters:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
gardeners:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

Display struts output to jsp

 
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to display userList from my struts action to jsp page,what's the code to do it using java beans or something simple?

part code:
action class
------------------------------------------------------------------------------------------------------------------------
public ArrayList userList = new ArrayList();


public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {


//get connection from database
javax.sql.DataSource dataSource;
java.sql.Connection myConnection = null;



// Here the method that connects to the datasource is called:
dataSource = getDataSource(request);
myConnection = dataSource.getConnection();

UserDAO dao = DAOFactory.createUserDAO(myConnection);
userList = dao.getUser();
HttpSession session = request.getSession();

// extract data
if(userList !=null){

//code here
return mapping.findForward("success");
}else{
return mapping.findForward("fail");
}



}
 
pioneer
Posts: 190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
request.setAttribute("userListBean",userList);
 
leo oke
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply..
However, I've created the bean class ...below,but I don't see the output userlist only hello...why?

part code;
-----------------------
public class UserListBean {

public ArrayList userList;

public ArrayList getUserList() {
return userList;
}

public void setUserList(ArrayList userList) {
this.userList = userList;
}

public UserListBean(ArrayList userList) {
this.userList = userList;
}

---------------------------------------------------
The jsp out

part code

<title>success</title>
</head>
<body>

<h2>Hello</h2>

<logic resent name="UserListBean">

<h1>
Welcome: <bean:write name="UserListBean" property= "userList"/>
</h1>


</logic resent>






</body>
 
Chris Boldon
pioneer
Posts: 190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you set the response as I suggested in the action?
 
leo oke
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply again,I know is something simple making it not working,but I've put the response like this...

part code
----------------------------------------------------------------------------

public ArrayList userList = new ArrayList();


public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {

............................................................................

Is this correct or how is it done?
 
Chris Boldon
pioneer
Posts: 190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see you putting it in the response anywhere in that code snippet.
 
leo oke
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've put the response snipped in like this ....
HttpSession session = request.getSession();

in the code is this correct?
 
pioneer
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Leo,

Chris gave you the answer in his first reply: just put the list in the request, using the same name as in the .jsp (should not be difficult)

request.setAttribute("UserListBean",userList);

Herman
 
I'm still in control here. LOOK at this tiny ad!
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!