Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

compiling servlets

 
vidhya subramaniam
Ranch Hand
Posts: 91
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>");
}
}
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13044
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
Bal Sharma
Ranch Hand
Posts: 273
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>");
}
}

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic