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
posted
0
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: 3219
posted
0
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
posted
0
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: 3219
posted
0
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
posted
0
Thank you very much Tony! I had general idea like the way you have mentioned. Thanks for your detailed explanation. Appreciate your help.