aspose file tools*
The moose likes Servlets and the fly likes Bean or Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Bean or Servlet" Watch "Bean or Servlet" New topic
Author

Bean or Servlet

Joseph Smithern
Ranch Hand

Joined: Feb 11, 2006
Posts: 89
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

Joined: Jan 10, 2002
Posts: 60077
    
  65

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 ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Joseph Smithern
Ranch Hand

Joined: Feb 11, 2006
Posts: 89
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

Joined: Mar 10, 2006
Posts: 64
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

Joined: Feb 11, 2006
Posts: 89
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

Joined: Jan 24, 2005
Posts: 489


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.
 
wood burning stoves
 
subject: Bean or Servlet
 
Similar Threads
how to create common successful page
A Design Question.
JSP to Bean to Servlet
request.getAttribute from servlet on jsp page load
character encoding from jsp->servlet