• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Display struts output to jsp

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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");
}



}
 
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
request.setAttribute("userListBean",userList);
 
leo oke
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you set the response as I suggested in the action?
 
leo oke
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't see you putting it in the response anywhere in that code snippet.
 
leo oke
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've put the response snipped in like this ....
HttpSession session = request.getSession();

in the code is this correct?
 
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
All of the following truths are shameless lies. But what about this tiny ad:
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic