Forums Register Login

compiling servlets

+Pie Number of slices to send: Send
HI,
I have written a simple servlet and tried compiling in the dos prompt givin javac Servlet01.java. but it gives me an error on line 11 saying class printWriter not found. can someone pl explain the error.
Also, once i compile the servlet how do i view it in the browser. is there any good notes available on the web for compiling and running servlets.
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Servlet01 extends HttpServlet{
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException,IOException{
res.setContentType("text/html");
printWriter out = res.getWriter(); // line 11
out.println("<HTML>");
out.println("<HEAD><TITLE = SERVLET01></TITLE></HEAD>");
out.println("<BODY>");
out.println("Hello Big World");
out.println("</BODY></HTML>");
}
}
+Pie Number of slices to send: Send
Thats an easy one - the class you want is PrintWriter
Note the upper case first letter.
Java style calls for class names to start with a upper case letter, while variable names start with lower case.
Bill
------------------
author of:
+Pie Number of slices to send: Send
Your printWriter is in lower case. Type it in uppercase as PrintWriter and try it.

Originally posted by vidhya subramaniam:
HI,
I have written a simple servlet and tried compiling in the dos prompt givin javac Servlet01.java. but it gives me an error on line 11 saying class printWriter not found. can someone pl explain the error.
Also, once i compile the servlet how do i view it in the browser. is there any good notes available on the web for compiling and running servlets.
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Servlet01 extends HttpServlet{
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException,IOException{
res.setContentType("text/html");
printWriter out = res.getWriter(); // line 11
out.println("<HTML>");
out.println("<HEAD><TITLE = SERVLET01></TITLE></HEAD>");
out.println("<BODY>");
out.println("Hello Big World");
out.println("</BODY></HTML>");
}
}


If you're gonna buy things, buy this thing and I get a fat kickback:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 995 times.
Similar Threads
Servlets example
Package not found error on running servlet !
Error 404: File not found: loadservlet
New to servlets
Hello world ejb3 problem
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 19, 2024 03:11:31.