wood burning stoves 2.0*
The moose likes Servlets and the fly likes HTTP servlet problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "HTTP servlet problem" Watch "HTTP servlet problem" New topic
Author

HTTP servlet problem

Sanjeev Arora
Greenhorn

Joined: Apr 30, 2001
Posts: 21
Servlet gurus,
I have a strange problem. Well, it might not be strange for everybody but at least it is for me. I have Tomcat version 4.0 installed on Windows 2000. I have my CLASSPATH variable correctly set. In fact, if my servlet (which extends HttpServlet) works just fine and displays all the HTML tags when run. However, when I add this extra line of code, it does not display today's date. Also when I do a 'view source' in the browser (IE 5.0), it does not display the line of HTML code either.
Here's the code:
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class SimpleServlet extends HttpServlet
{
/**
* Handle the HTTP GET method by building a simple web page.
*/

String today = (new Date()).toString();
public void doGet (HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
PrintWriterout;
Stringtitle = "Simple Servlet Output";
// set content type and other response header fields first
response.setContentType("text/html");
// then write the data of the response
out = response.getWriter();
out.println("<HTML><HEAD><TITLE>");
out.println(title);
out.println("</TITLE></HEAD><BODY>");
out.println("<H1>" + title + "</H1>");
out.println("<P>This is output from the <b>SimpleServlet</b>.");
out.println("How does it look like?");
&&& out.println("<P>Today's date is: "+today+"<P>");
out.println("</BODY></HTML>");
out.close();
}
}
The line that is not displayed is annotated with &&&. The other funny thing is that the file compiles successfully.
Can someone please help me out?
Thank you,
Sanjeev
Ganesh Anekar
Ranch Hand

Joined: May 13, 2001
Posts: 36
Hello,
Try using this..
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class simpleservelet extends HttpServlet
{
public void doPost(HttpServletRequest req,HttpServletResponse res) throws
ServletException,java.io.IOException
{
doGet(req,res);
}
public void doGet(HttpServletRequest req,HttpServletResponse res) throws
ServletException,java.io.IOException
{
res.setContentType("text/html");
java.io.PrintWriter out=res.getWriter();

//ServletContext s=getServletContext();
HttpSession session=req.getSession(true);
/*
your code
*/
Ganesh

Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
Did you restart your Tomcat server after adding your new line, compiling your file, and putting the class file where Tomcat can see it? Tomcat will cache class files, and often needs a restart to pick up the latest versions.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Ganesh Anekar
Ranch Hand

Joined: May 13, 2001
Posts: 36
Hi,
Actually That is the Bug of tomcat and it is reported in tomcat bug report...

U can not use tomcat for development...when u change any code and recompile it...to see that effect each time u have to restart u r tomcat server....

Ganesh
Sanjeev Arora
Greenhorn

Joined: Apr 30, 2001
Posts: 21
Thanks guys. Unfortunately, I'd already tried shutting down and restarting Tomcat - before I posted my first message - since I knew about this bug. The new line of code never got displayed. Before trying Ganesh's code, I would like to first understand why my original code is not displayed completely. Any suggestions/advice are/is welcome.
Thanks,
Sanjeev
Sanjeev Arora
Greenhorn

Joined: Apr 30, 2001
Posts: 21
I put in Ganesh's code and then added the HTML inside the 'doGet' method. I still keep getting the same output as I did before I added the date field. When I do a 'view source' on the browser, I get the old tags. It looks like Tomcat has somehow cached my original servlet. I have no clue how to handle this. Can you guys please help?
Thanks a lot,
Sanjeev
maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
It is a dirty check . Just change the name of the servlet and try calling from browser.
I checked with TOmcat3.1 and got the new output after restarting tomcat.
regds
maha anna
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: HTTP servlet problem
 
Similar Threads
Compiling the servlet
how to use ssi in servlets using apache web server and jserv
new, need help!!!
Basic Servlet Problem
HttpServletResponse& HttpServletRequest