File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

problem executing the servlet

trupti nigam
Ranch Hand

Joined: Jun 21, 2001
Posts: 613
Hi,
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.io.*;
import java.net.*;
import java.util.*;
public class ShowSession extends HttpServlet
{
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
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";
}
else
{
heading = "Welcome back";
accessCount = new Integer(accessCount.intValue()+1);
}

session.setAttribute("accessCount",accessCount);
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"+
"<tr>\n"+
"<td>ID\n"+
"<TD>"+session.getId()+"\n"+
"<tr>\n"+
"<td>Creation time\n"+
"<td>"+
new Date(session.getCreationTime())+"\n"+
"<tr>\n"+
"<td>Time of last Access\n"+
"<td>"+
new Date(session.getLastAccessedTime())+"\n"+
"<tr>\n"+
"<td> Number of previous accesses\n"+
"<td>"+accessCount+"\n"+
"</table>\n"+
"</body></html>");

}

public void doPost(HttpServletRequest request,HttpServletResponse response)
throws ServletException, IOException
{
doGet(request,response);
}

}
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..
trupti
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.

Thambi
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.
Thanks.
trupti nigam
Ranch Hand

Joined: Jun 21, 2001
Posts: 613
Hi Thambi and engin..
I didn't get any compilation error..so 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.)
thanks
Trupti
 
wood burning stoves
 
subject: problem executing the servlet