Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > servlet/jsp/jdbc best approach

Reply
Thread Tools

servlet/jsp/jdbc best approach

 
 
Email2us
Guest
Posts: n/a
 
      06-23-2005
Hello guys

Which is the best approach when developing servlet/jsp/jdbc? I will take an
example:

I have index-page, page2 and page 3.

When the user writes www.mydomain.com then the page index.jsp checks if the
user is coming from the servlet, like this:

<%
if(request.getAttribute("getPageTitle")==null){
%>
<jsp:forward page="/Index" />
<%
}
else{
%>
<%@ include file="/include/header.jsp" %>
content for index.jsp
<%@ include file="/include/footer.jsp" %>
<%
}
%>

On the other hand, the Index class has this init()

public void init(ServletConfig config) throws ServletException {
super.init(config);
con = DatabaseConf.getConnection();
}

DatabaseConf is a class that handles all the operations related to the
database.

Index.class has also the doGet-method like this:

request.setAttribute ("getPageTitle", "AnyTilte");
getServletConfig().getServletContext().getRequestD ispatcher("/index.jsp").forward(request,
response);

Does it looks ok so long?

Now, I have other pages, page2 and page3 (in fact I have mych more than just
these, but this is only an example)

pages.jsp works as index.jsp. It makes a check
<%
if(request.getAttribute("getPageTitle")==null){
%>

if not satisfied than it redirect to

<jsp:forward page="/Page2" />

My concern, however, is about databasemanagement. Even the Page.class has an
init-method that looks exactly like the one in Index.class, e.g.

public void init(ServletConfig config) throws ServletException {
super.init(config);
con = DatabaseConf.getConnection();
}

In conclusion, Im starting jdbc-connection for every class-file that
initiates. Is this a good approach? What I would like is a solution to
initiate the database only one time, when the server starts. Not everytime,
the first time a specially class-file will be called. I know, this will
happens only one time for a file for the server's lifetime. But Im afraid
this is not a good way to work.

Regards

email2us









 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Core Exams - Best approach to take? =?Utf-8?B?R2F2aW4=?= MCSE 1 02-02-2006 03:29 PM
Best Approach? Conditionally checking a CheckBoxList item if record is found.. D. Shane Fowlkes ASP .Net 0 05-11-2004 07:40 PM
Multithreading Async aspx best approach milesm ASP .Net 1 05-06-2004 12:24 AM
Help - Best approach using Shared Classes ? Paul ASP .Net 3 04-30-2004 07:00 PM
Best approach to bind data from XML to an asp:Table Greg Linwood ASP .Net 4 12-03-2003 05:44 PM



Advertisments