Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Bean or Servlet

 
Joseph Smithern
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a form with 3 inputs (Firstname, LastName and Job Title).

I need to search a MySQL database and find information with 1 or more of the fields entered in.

Please advise if this should be done using a JSP for the Form input page and a Servlet for the action page that searches the database? If so can someone provide a quick psuedo Servlet code?

Or should I do it with a JSP for the Form and use a Bean for the action page?
[ July 07, 2006: Message edited by: Joseph Smithern ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64967
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you can't submit to a bean at all. If you are talking about submitting to a JSP that employs a bean, then that's possible, but ill-advised.

Your processing should occur (or be controlled by) a servlet.

Please read this article on web app structure, paying particular attention to the PRG pattern.
[ July 07, 2006: Message edited by: Bear Bibeault ]
 
Joseph Smithern
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,

I read and printed out that article and will use it.

Last week I completed a form that uses a JSP that employs a Bean and it works great with my form offering three fields where 1 or more form entries can search for information in my database.

My next step is to create a JSP form page for entering and modifying the database and I will use Servlet for the action page which I assume is the correct way to do that.

Please advise what negative effects I could possibly have with my current JSP search page that employs a Bean?

Here is how the JSP calls the Bean that is working for me:


[ July 09, 2006: Message edited by: Joseph Smithern ]
[ July 09, 2006: Message edited by: Joseph Smithern ]
 
abhijit Ohal
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jsp is for presention purpose so as far as posible keep Buisness logic in this case DataBase conn in servlet.
As jsp doesn't have good exception handling.

So in Above case From every request code is fetching first name ,Last Name . inStead of keep employee object (i.e Employee bean as Your using) in request.
 
Joseph Smithern
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would just need to remove the URL property where I am connecting to the database and put that in my Bean and my JSP will then fully seperate Presentation from Business?
 
ramprasad madathil
Ranch Hand
Posts: 489
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I would just need to remove the URL property where I am connecting to the database and put that in my Bean and my JSP will then fully seperate Presentation from Business?


No. You'll have to do have a Servlet receive the request, instantiate the bean, set the bean properties from request and then call database operation methods on it, retrieve the result, set the result as a scoped attribute, and finally forward to a jsp.

ram.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic