File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes cannot find symbol method setContentType Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "cannot find symbol method setContentType" Watch "cannot find symbol method setContentType" New topic

cannot find symbol method setContentType

utsav gupta
Ranch Hand

Joined: Mar 19, 2009
Posts: 57
Hi I'm trying to run a servlet but i'm getting this exception on compiling the servlet My program is

import javax.servlet.*;
import javax.servlet.http.*;

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

public void doPost(HttpServletRequest req,HttpServlet res) throws

PrintWriter out=res.getWriter();

String id=req.getParameter("id");
String password =req.getParamter("ped");

if("jsmith".equalsIgnorecase(id) && "Spring12".equalIgnoreCase(password))
out.println("Hello "+ id +". Welcome to our magazines! ");
out.println("Invalid ID or password");

The exception is cannot find symbol
symbol : method setContentType(java.lang.String)
location: class javax.servlet.http.HttpServlet

Please help.

Uli Hofstoetter
Ranch Hand

Joined: Nov 24, 2006
Posts: 57
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.


btw ... setContentType is a method of ServletResponse and HttpServletResponse, and not of HttpServlet, of which type your res is.

SCEA5, Certified ScrumMaster
utsav gupta
Ranch Hand

Joined: Mar 19, 2009
Posts: 57
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.

I agree. Here's the link:
subject: cannot find symbol method setContentType
It's not a secret anymore!