File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

cannot find symbol method setContentType

 
utsav gupta
Ranch Hand
Posts: 57
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I'm trying to run a servlet but i'm getting this exception on compiling the servlet My program is



import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;



public class LoginServlet extends javax.servlet.http.HttpServlet {




public void doPost(HttpServletRequest req,HttpServlet res) throws

ServletException,IOException{
res.setContentType("text/html");
PrintWriter out=res.getWriter();

String id=req.getParameter("id");
String password =req.getParamter("ped");
out.println("<HTML><BODY>");

if("jsmith".equalsIgnorecase(id) && "Spring12".equalIgnoreCase(password))
{
out.println("Hello "+ id +". Welcome to our magazines! ");
}
else{
out.println("Invalid ID or password");
}
out.println("<BODY></HTML>");
}
}

The exception is

LoginServlet.java:14: cannot find symbol
symbol : method setContentType(java.lang.String)
location: class javax.servlet.http.HttpServlet
res.setContentType("text/html");


Please help.
Thanks.







 
Uli Hofstoetter
Ranch Hand
Posts: 57
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use code tags to make code easier to read.

In which container do you try it to run and what is the whole exception?
Or do you speak of something else when saying "run". Please be more specific when describing errors, this will make it easier for people to help you.


Regards,
Uli

btw ... setContentType is a method of ServletResponse and HttpServletResponse, and not of HttpServlet, of which type your res is.
 
utsav gupta
Ranch Hand
Posts: 57
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Uli

Thanks for your help.
I changed the res object type to HttpServletResponse and it worked.

By the way i use tags but it got all unformatted on pasting.

Regards
Utsav.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic