• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

cannot find symbol method setContentType

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.







 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic