File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

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 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

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.


Regards,
Uli

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.

Regards
Utsav.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: cannot find symbol method setContentType