File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes problem executing the servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "problem executing the servlet" Watch "problem executing the servlet" New topic

problem executing the servlet

trupti nigam
Ranch Hand

Joined: Jun 21, 2001
Posts: 614
I have a problem executing the following servlet code:
The servlet class is stored under the proper directory structure.
That is myDevelopment/WEB-INF/classes/myServlets/ShowSession
myDevelopment is stored under the tomcat/webApps.
I have set the context to myDevelopment directory in the servlet.xml file
The code is:
package myServlets;

import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
public class ShowSession extends HttpServlet
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException, IOException
PrintWriter out = response.getWriter();
String title = "Session tracking example";
HttpSession session = request.getSession(true);
String heading;
Integer accessCount = (Integer)session.getAttribute("accessCount");
if(accessCount == null)
accessCount = new Integer(0);
heading = "Welcome, newcomer";
heading = "Welcome back";
accessCount = new Integer(accessCount.intValue()+1);

String docType = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n";
out.println(docType + "<Html>\n"+"<head><title>"+ title+
"<body bgcolor = \" #FDF5E6\">\n"+
"<H1 align=\"center\">"+ heading +"</H1>\n"+
"<h2>Information on your Session:</h2>\n"+
"<table border=1 align=\"center\">\n"+
"<tr BGCOLOR=\"#FFAD00\">\n"+
"<th>Info Type<Th>Value\n"+
"<td>Creation time\n"+
new Date(session.getCreationTime())+"\n"+
"<td>Time of last Access\n"+
new Date(session.getLastAccessedTime())+"\n"+
"<td> Number of previous accesses\n"+


public void doPost(HttpServletRequest request,HttpServletResponse response)
throws ServletException, IOException

whenever I try to access the above servelt through the URL: http://localhost/myDevelopment/servlet/myServlets.ShowSession
I don't get any kind of error but the browser doesn't show any HTML code..I mean it displays blank browser..
any help is appreciated..
thaks in advance..
Thambi Rajah
Ranch Hand

Joined: Jul 19, 2002
Posts: 36
Hello trupti,
In your doGet() method, the tags <title>, <head> were not closed properly. I concatenated "</title></head>"+
to your original code, it works fine. I also noticed some of your <td>,<tr> tags also were not closed properly.

Engin Okucu
Ranch Hand

Joined: Feb 09, 2002
Posts: 174
Hi Trupti,
I did try your code. It did not work because you forgot the enclosing tag of 'title'...
Then you must add "</title>" in your Html code.
trupti nigam
Ranch Hand

Joined: Jun 21, 2001
Posts: 614
Hi Thambi and engin..
I didn't get any compilation never bothered to check my code..for HTML stuff.
Thanks a lot..
I didn't knew that a small mistake in html code can cause these kinds of errors..(not exactly errors..but wierd result.)
I agree. Here's the link:
subject: problem executing the servlet
It's not a secret anymore!