wood burning stoves 2.0*
The moose likes Servlets and the fly likes need of Design Pattern with servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "need of Design Pattern with servlet" Watch "need of Design Pattern with servlet" New topic
Author

need of Design Pattern with servlet

Hareesh Ram Chanchali
Ranch Hand

Joined: Jan 31, 2005
Posts: 110
hi,

I am writing a servlet which updates multiple database tables at once...
now I have a HTML front end file and a servlet. and I am printing the output about successful and unsuccessful insertion using out.print() where out is a PrintWriter to Response object of servlet

Total business logic is there in the servlet

My questions are

1. Is it possible for me to adopt MVC pattern for this

2. if not How I should organize my code...How to divide and place....

3.Where to keep the output info....


Hareesh Ram Chanchali
SCJP 5.0, IBM Certified Solution Designer
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

  • Browser hits servlet (controller) and gets forwared to the JSP (view) with the form
  • User fills out form and submits. Form is submitted to the servlet.
  • Servlet parses form parameters. If OK, instanciates bean (model) and passes values to it. The bean has all the JDBC code in it.
  • The bean performs all database function and returns results (possibly in the form of another bean) to the servlet.
  • The servlet binds the results to the request object and forwards to the JSP for display.
  • The JSP (using either jsp:getProperty or EL, or JSTL..) presents the results to the user.


  • Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
    Hareesh Ram Chanchali
    Ranch Hand

    Joined: Jan 31, 2005
    Posts: 110
    hi ben,

    I am updating 20 to 30 tables on a single click..
    It is an application of Data Population from MS-Excel file to Oracle...

    I wont fill the data in forms ...only the input i give is the file name with location... I should be able to display about successful/unsuccessful insertions rowwise
    Adeel Ansari
    Ranch Hand

    Joined: Aug 15, 2004
    Posts: 2874
    Do as Ben directed. Then put some logic while inserting data in tables. You can populate a collection of a Bean, which would have appropriate message in it. Then bind that collection with your request object, and so forth. . . so forth.
    Ben Souther
    Sheriff

    Joined: Dec 11, 2004
    Posts: 13410

    You'll also want to look into a file upload library.
    I use http://jakarta.apache.org/commons/fileupload
     
     
    subject: need of Design Pattern with servlet
     
    Similar Threads
    *.faces suffix mapping
    Multiple url-pattern in filter-mapping OC4j 10.1.3.3 Servlet 2.5
    Change URL http/unbeatableonline.com/swbeatableonline.com to http/unbeatableonline.com
    problem with using URIs as parameters
    URL rewriting in Struts1