Hi I am new to Jsp,Please help me.

This is my Jsp Program:
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class login extends HttpServlet {
private String target = "/welcome.jsp";
private String getUser(String username, String password) {
// Just return a static name
// If this was reality, we would perform a SQL lookup
return "Frodo";
public void init(ServletConfig config)
throws ServletException {
super.init(config);
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
// If it is a get request forward to doPost()
doPost(request, response);
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
// Get the username from the request
String username = request.getParameter("username");
// Get the password from the request
String password = request.getParameter("password");
String user = getUser(username, password);
// Add the fake user to the request
request.setAttribute("USER", user);
// Forward the request to the target named
ServletContext context = getServletContext();
RequestDispatcher dispatcher =
context.getRequestDispatcher(target);
dispatcher.forward(request, response);
public void destroy() {
when i compile this i got this error:
cannot find symbol:
setAttribute()
request.setAttribute("USER",user);
cannot find symbol:
class RequestDispatcher
RequestDispatcher dispatcher =
context.getRequestDispatcher(target);

Hey no need of that . you can use request scoped attributes too.
and remember this is not JSP. it's a SERVLET
your code is completely correct. there are no errors in it. i am pasting your code. just check it.
It's working properly. no compile time errors occured.
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class login extends HttpServlet {
     private String target = "/welcome.jsp";
     private String getUser(String username, String password) {
//          Just return a static name
//          If this was reality, we would perform a SQL lookup
          return "Frodo";
     public void init(ServletConfig config)
     throws ServletException {
          super.init(config);
     public void doGet(HttpServletRequest request,
               HttpServletResponse response)
     throws ServletException, IOException {
//          If it is a get request forward to doPost()
          doPost(request, response);
     public void doPost(HttpServletRequest request,
               HttpServletResponse response)
     throws ServletException, IOException {
//          Get the username from the request
          String username = request.getParameter("username");
//          Get the password from the request
          String password = request.getParameter("password");
          String user = getUser(username, password);
//          Add the fake user to the request
          request.setAttribute("USER", user);
//          Forward the request to the target named
          ServletContext context = getServletContext();
          RequestDispatcher dispatcher =
               context.getRequestDispatcher(target);
          dispatcher.forward(request, response);
     public void destroy() {
}Let me know where you are getting issues exactly.
Diablo

Similar Messages

Maybe you are looking for

  • PL/SQL vs Pro*C / Cobol

    Can any one tell me whether PL/SQL can totally replace Pro*C / Cobol? I remember there is a PL/SQL package called UTL_FILE, which enable user to do File I/O. However, I wonder whether it really excel the File I/O capability of the conventional Cobol

  • Consuming web services provided 3rd

    Hello experts, I have a scenario SAP -> XI -> 3rd party WS (with multiple actions) The 3rd party WS contains several actions for manipulating a Business Object. I would like to define one Inbound Service Interface with several Operations for consumin

  • Trying to find Java release 1.6.0.1_45, any ideas

    Trying to find Java release 1.6.0.1_45, any ideas

  • 11g rel 2 RAC on RHEL5.2

    TASK: need to install 11g rel 2 RAC on a two node RHEL (2.6.18-128.el5 #1 SMP Wed Dec 17 11:41:38 EST 2008 x86_64 x86_64 x86_64 GNU/Linux). What are the RPM's needed for the cluster installation? Regards,Lily.

  • Can't change the media type in iTunes

    I just recently bought my first MBP and I have been busy transferring all my files from my Vaio to my MBP. I convert all my dvds to digital format and keep them on an external HDD (LaCie 1TB HDD) and was adding them to my iTunes on my MBP. I came acr