Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts2MySQL

 
Chandana Garlapati
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how do we create the bean class separately(not in struts2 action class) and how to pass those values in mysql using action class???
 
Joe Ess
Bartender
Posts: 9312
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chandana Garlapati wrote:how do we create the bean class separately(not in struts2 action class)


What bean? A bean to encapsulate form data? I usually let Struts create it. See the CRUD Demo.

Chandana Garlapati wrote:
and how to pass those values in mysql using action class???


This FAQ entry was written for Struts 1.2, but I think it still applies to Struts 2.x. Struts is an implementation of the Front Controller pattern, so it has little to do with back-end tasks like database access.
 
Chandana Garlapati
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Joe....

How to retrieve the auto-increment value from MySQL to JSP page using struts2??
 
Joe Ess
Bartender
Posts: 9312
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at this page from the MySQL 5.0 Reference Manual
 
Chandana Garlapati
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is my Action class


struts.xml



and JSP



And i need to retrieve MemberNumber on JSP which is generated on MySQL.
how to get that???
 
Joe Ess
Bartender
Posts: 9312
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you read the link I posted? MySql provides a function to retrieve the last inserted ID.
BTW, it is bad design to put all your logic in the Action class. It's fine for experimenting, but you'll want to have a look at this page from the Struts 1.x docs.
 
Chandana Garlapati
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok thanks Joe...


how to use last_insert_id() function in JSP using Struts2???
 
Joe Ess
Bartender
Posts: 9312
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are not going to use the function in the JSP. You are going to retrieve the value in your Action (or better, a class the Action invokes) and pass it back to a JSP.
 
Chandana Garlapati
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Finally i retrieved my membernumber value in action class.
Can you tell me how to pass this value to JSP???
 
Joe Ess
Bartender
Posts: 9312
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You make the value accessible via a getter in your acton and print it out on the JSP with a JSP tag.
 
Chandana Garlapati
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you show me how to pass that value in my code???
 
Joe Ess
Bartender
Posts: 9312
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at the Struts 2 Beginner Tutorial.
 
Chandana Garlapati
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
solved it finally,


thank you very much Joe...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic