File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Display struts output to jsp

 
leo oke
Greenhorn
Posts: 21
  • 0
  • 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");
}



}
 
Chris Boldon
Ranch Hand
Posts: 190
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
request.setAttribute("userListBean",userList);
 
leo oke
Greenhorn
Posts: 21
  • 0
  • 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
Ranch Hand
Posts: 190
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you set the response as I suggested in the action?
 
leo oke
Greenhorn
Posts: 21
  • 0
  • 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
Ranch Hand
Posts: 190
  • 0
  • 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
Greenhorn
Posts: 21
  • 0
  • 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?
 
Herman Schelti
Ranch Hand
Posts: 387
  • 0
  • 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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic