• 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

Adding items from jsp to a list in java

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry wrongly posted above one
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic