aspose file tools*
The moose likes Struts and the fly likes Adding items from jsp to a list in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Adding items from jsp to a list in java" Watch "Adding items from jsp to a list in java" New topic
Author

Adding items from jsp to a list in java

Yatika Sharma
Greenhorn

Joined: Aug 26, 2011
Posts: 18
Hi...

I am trying to create an application using struts2 and using hibernate for database connections. I have used JSP for front end. In one of my page i have several items and a button next to every item created using anchor tag in html. I want that when user clicks any of the button corresponding to its item that item should be inserted in a List in java so that i can add it to my db using hibernate in my action class.Also, as the user selects items, the selected one should be displayed in a box at the bottom of JSP.

Does anyone has any idea how to do it in the best possible way?
Please help.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10205
    
166

You are asking for a lot of things in that one question. Questions like these don't usually get answers because they are too vague or require too much explanation.

Let's try and split up your question.

I want that when user clicks any of the button corresponding to its item that item should be inserted in a List in java so that i can add it to my db using hibernate in my action class

1) Have you implemented the page? Do you have the buttons showing up? If not, then first write up simple page with maybe just one button and let the on click action trigger some change

2) Have you worked with Struts before? If not, then I would suggest that you find some decent tutorials and go through some examples before applying it in your application

3) Once you know how Struts is setup and how to map the page actions to your Java code (action classes), it won't take long to implement it.

4) As for Hibernate, that's a completely different part. Have you worked with Hibernate? If not, find some good tutorials and try out some sample applications.

Overall, break down your tasks into smaller subtasks and implement that one at a time. Once that's done, it will be easier to just tie them together in your application


[My Blog] [JavaRanch Journal]
seenu java
Greenhorn

Joined: Oct 03, 2011
Posts: 12
you have to implement interceptor for that,check this works out for you?

public class LoginInterceptor extends AbstractInterceptor {

private static final String USER = "user";


public String intercept (ActionInvocation invocation) throws Exception {
// Get the action context from the invocation so we can access the
// HttpServletRequest and HttpSession objects.
final ActionContext context = invocation.getInvocationContext ();
HttpServletRequest request = (HttpServletRequest) context.get(HTTP_REQUEST);
HttpSession session = request.getSession (true);

Object user = session.getAttribute (USER);
if (user != null) {
// The user already logged in..
return invocation.invoke (); // send to other interceptor/other page

} else {
return "login"; // if login failed/invalid user redirecting to login page(configure in struts.xml file)
}
}
}
seenu java
Greenhorn

Joined: Oct 03, 2011
Posts: 12
sorry wrongly posted above one
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Adding items from jsp to a list in java