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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Jsp or Servlet" Watch "Jsp or Servlet" New topic
Author

Jsp or Servlet

Mandy Smith
Ranch Hand

Joined: Jun 26, 2001
Posts: 62
I am not sure whether to write a jsp page or a servlet.
I have lot of html contents to be included and some dynanmic contents fetched from database(like name, phone,email etc). I am not comfortable to do the database connection in a jsp page, where as if i go for a servlet i need to append lot of html contents to my buffer. So could anyone please suggest me what to go for.
Appreciate your suggestion!
Thanks.
Mahesh Rana
Ranch Hand

Joined: Sep 05, 2001
Posts: 139
I would say,
have your servlet hook on to the database
and generate the XML.
And let an XSL take care of the presentation.


SCJP2
Tony Alicea
Desperado
Sheriff

Joined: Jan 30, 2000
Posts: 3222
    
    5
I would recommend create a data bean that has all the information in it, place it in the request object, and forward to a JSP that would use the bean to fill in the dynamic content. Most of the page would be static HTML and you could do away with XML/XSL.
This is precisely the reason to use Servlets and JSPs.
[This message has been edited by Tony Alicea (edited October 08, 2001).]


Tony Alicea
Senior Java Web Application Developer, SCPJ2, SCWCD
Mandy Smith
Ranch Hand

Joined: Jun 26, 2001
Posts: 62
Tony, i think, its a good idea to create a data bean. I have never done this before. Could you please assist me.
Did you mean to fetch the data from the database and store all the required info in this bean, so that i have access to all info using get methods. I need to fetch user info from the session which i am using in my sql query. In my Data Bean i don't have access to session object. This jsp page only displays data and i don't require to do any processing part. This jsp page not only displays the data from one table but from several tables. So do you think i need to create separate data beans pertaining to particular table.
Also i am not clear with how to place the data bean in the request object and forwarding it to a jsp.
Could you please elaborate on this.
Appreciate your help!
Thank you.
Tony Alicea
Desperado
Sheriff

Joined: Jan 30, 2000
Posts: 3222
    
    5
You almost answered yourself the question
I'd define a JavaBean class (w/get, set etc...) that has all the fields needed by the JSP to display the user info.
The servlet would do the DB call and set all the required fields (properties) of the bean.
The servlet would place the bean in the request by calling
req.setAttribute("myBean", bean)
In the JSP you have two choices but I'd use the
<jsp:useBean id="myBean" CLASS="..." SCOPE="request" .../>
and then populate the fields like
Name: <%= myBean.getName() %>
Others??
Mandy Smith
Ranch Hand

Joined: Jun 26, 2001
Posts: 62
Thank you very much Tony! I had general idea like the way you have mentioned. Thanks for your detailed explanation.
Appreciate your help.
Ray Smilgius
Ranch Hand

Joined: Jan 29, 2001
Posts: 120
Can Anyone recommend a good jsp/servlet book?


SCJO, SCJD, SCWCD, I-Net+, A+, Network+, MCSD, MCDBA, MCP, MCT
 
 
subject: Jsp or Servlet
 
Similar Threads
form contents
Servlet problem concerning form data
Running servlets from with jsp
Addressing dynamic table elements
stay with same page after submiting form