• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

I can't get the struts working

 
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 got a struts database that I want to forward the success database result to a jsp page.
I've built the logic class and the interface to connect to the database ,but the action class has the problem.
I want to pass the userList from the logic class into the action class then forward it to the jsp page!
I tried this code but get an error..How is it done ? any help

part code

logic class
// Creates a new instance of MysqlUserDAO
public MySqlUserDAO(Connection myConnection){
this.myConnection = myConnection;

}

public ArrayList getUser(LoginForm form) {

ArrayList userList = new ArrayList();
try {
String query = "SELECT * FROM `role` NATURAL JOIN `user` WHERE username = '"+form.getName() +"' ";
Statement stmt = myConnection.createStatement();
ResultSet rs =stmt.executeQuery(query);

// extract data from the ResultSet
while(rs.next()){
// /** Here we put role into the userist: */
String role = rs.getString("role");
userList.add(rs.getString("role"));

.........................
return userList;
.............................


interface class
public interface UserDAO {

public ArrayList getUser(LoginForm form);

}

part code
action class

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

HttpSession session = request.getSession();

//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);

//Below code is the part which I have the problem ,I want to pass the userList from the logic class

------> userList = dao.getUser(LoginForm form); <--------- this is where the problem lays. Its not correct ,there must be away bring the userList to the action class?
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In order for this list to be used, you have to put it somewhere the JSP can access it. The most common place to put objects to be accessed by the JSP is in the HTTPServletRequest object. Something like this would work:

Then in your JSP, you could use a combination of logic:iterate and bean:write tags to display the contents of the list.
 
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 effort,but the problem lays passing the userList from the logic class to the action class.
So the syntax 'userList =dao.getUser(LoginFrom form);' is not correct for retrieving the userList.
therefore how's done?
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by leo oke:
Thanks for your effort,but the problem lays passing the userList from the logic class to the action class.
So the syntax 'userList =dao.getUser(LoginFrom form);' is not correct for retrieving the userList.
therefore how's done?


Just change it to:

When you call a method, you don't need to declare the type of the parameters you pass.

What I was trying to point out, though, is that while the above statement is syntactically correct, it just assigns a local variable named userList to a an ArrayList retrieved from another method. Since this is a local variable, it's completely useless unless you put the data somewhere that the JSP has access to.
[ October 08, 2007: Message edited by: Merrill Higginson ]
 
It was the best of times. It was the worst of times. It was a tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic