这是LoginServlet.java
package server;import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.naming.*;/**
 * This is the very first servlet the client deals with.
 * It's a Login authentication servlet. It asks the user
 * for his name and password, and pass it to the UserManager
 * stateless session bean for verificatiion.
 * If the user authenticates properly, reference to a new
 * Cart is saved in his HttpSession object, and the user can
 * begin to add items to his cart and shop around.
 */
public class LoginServlet extends HttpServlet { /*
  * UserManager home object for authenticating user
  */
 private UserManagerHome userManagerHome; /*
  * Cart home object for creating a new cart when
  * the user logs in.
  */
 private CartHome cartHome; /**
  * The servlet engine calls this method once to
  * initialize a servlet instance.
  *
  * In the body of this method, we acquire all the
  * EJB home objects we'll need later.
  */
 public void init(ServletConfig config) throws ServletException {  super.init(config);  try {
   /*
    * Get the JNDI initialization parameters.
    * We externalize these settings to the
    * servlet properties to allow end-
    * users to dynamically reconfigure their
    * environment without recompilation.
    */
   String initCtxFactory =
    getInitParameter(Context.INITIAL_CONTEXT_FACTORY);   String providerURL =
    getInitParameter(Context.PROVIDER_URL);   /*
    * Add the JNDI init parameters to a
    * properties object.
    */
   Properties env = new Properties();
   env.put(Context.INITIAL_CONTEXT_FACTORY, initCtxFactory);
   env.put(Context.PROVIDER_URL, providerURL);   /*
    * Get the initial JNDI context using the above
    * startup params.
    */
   Context ctx = new InitialContext(env);   /*
    * Look up the UserManager and Cart Home Objects
    * we need via JNDI
    */
   userManagerHome = (UserManagerHome)
    ctx.lookup("UserManagerHome");   cartHome = (CartHome) ctx.lookup("CartHome");
  }
  catch (Exception e) {
   log(e);
   throw new ServletException(e.toString());
  }
 } /**
  * The servlet engine calls this method when the user's
  * desktop browser sends an HTTP request.
  */
 public void service(HttpServletRequest request,
                     HttpServletResponse response)
                     throws ServletException, IOException {  /*
   * Set up the user's HttpSession
   */
  HttpSession session = request.getSession(true);  /*
   * Retrieve the login name / password from the
   * URL string.
   */
  String loginName = request.getParameter("Login");
  String password = request.getParameter("Password");
  boolean isLogin=false;  /*
   * If user has not tried to log in yet, present
   * him with the login screen.
   */
  if ((loginName == null) || (password == null)) {
   writeForm(request, response, false);
  }  /*
   * Otherwise, the user has been to this screen
   * already, and has entered some information.
   * Verify that information.
   */
  else {
   /*
    * Uses the UserManager Stateless Session bean to
    * autenticate the user credentials.
    */
   try {
    UserManager  userManager=userManagerHome.create();
    isLogin= userManager.validateUser(loginName,password);
   }
   catch (Exception e) {
    writeForm(request, response, true);
    e.printStackTrace();
    return;
   }
   /*
    * If the passwords match, make a new Cart Session
    * Bean, and add it to the user's HttpSession
    * object.  When the user navigates to other
    * servlets, the other servlets can access the
    * HttpSession to get the user's Cart.
    */
   if (isLogin) {
    try {
     Cart cart = cartHome.create(loginName);
     session.setAttribute("cart", cart);     /*
      * Call the main page
      */
     RequestDispatcher disp =
      this.getServletContext().getRequestDispatcher("/wsf.jsp");
     disp.forward(request, response);     return;
    }
    catch (Exception e) {
     log(e);
     throw new ServletException(e.toString());
    }
   }
  }  /*
   * If there was no match, the user is
   * not authenticated.  Present another
   * login screen to him, with an error
   * message indicating that he is not
   * authenticated.
   */
  writeForm(request, response, true);
 } /**
  * Writes the Login Screen (private use only)
  *
  * @param showError true means show an error b/c client
  *        was not authenticated last time.
  */
 private void writeForm(HttpServletRequest request,
                        HttpServletResponse response,
                        boolean showError)
                        throws ServletException, IOException {  /*
   * Set a variable indicating whether or not we failed to
   * log-in.  The JSP will read this variable.
   */
  request.setAttribute("loginFailed", new Boolean(showError));  /*
   * Forward the request to the login JSP
   */
  RequestDispatcher disp =
   this.getServletContext().getRequestDispatcher("login.jsp");
  disp.forward(request, response);
 } private void log(Exception e) {
  e.printStackTrace();
 } public String getServletInfo() {
  return "The Login servlet verifies a user.";
 }
}错误是:Error 404--Not Found
From RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1:
10.4.5 404 Not Found
The server has not found anything matching the Request-URI. No indication is given of whether the condition is temporary or permanent.If the server does not wish to make this information available to the client, the status code 403 (Forbidden) can be used instead. The 410 (Gone) status code SHOULD be used if the server knows, through some internally configurable mechanism, that an old resource is permanently unavailable and has no forwarding address.谢谢各位了!!

解决方案 »

  1.   

    你的jbuilder下有servlet.jar吗?
      

  2.   

    你是说在required liberary中有没有servlet.jar吗?
    有哇!
      

  3.   

    你怎么调用的servlet? ------------------------------------------------------
               我们还年轻牛奶会有的奶牛也会有的 
                 可天天在 csdn 混这些会有吗 ??
      

  4.   

    friday1103(虞美人) :
    不知道你是怎么调用你的LoginServlet的,如果你这样调用LoginServlet看是不是在出错?
    如果你用的服务器是weblogic的话:
    http://localhost:7001/znn/LoginServlet,如果有问题在联系,我原来也遇到过这样的问题
      

  5.   

    lwg2019() :
    http://localhost:7001/znn/LoginServlet这样调用也有问题。
    zez(思恩 为老婆多挣钱 鹤清风):
    我看了你写的那个例子的。但是我这还是有问题。是这样调用servlet的。
    <form action="/znn/LoginServlet" method="get">
      

  6.   

    friday1103(虞美人)
    你是不 是应改为: <form action="/LoginServlet" method="get">
      

  7.   

    照你的web.xml配置来看,应该用<form action="/LoginServlet" method="get">,还有你试试:RequestDispatcher disp =
       this.getServletContext().getRequestDispatcher("/login.jsp");在login.jsp前加条“/”.好运!
      
      

  8.   

    我把jb7 与 weblogic 7 整合在一起后
    每次用jb8启动服务后,都在jb7中调用http://localhost:7001/loginServlet
    而且出现错误:Error 503--Service Unavailable是不是和你的错误差不多阿不知道改怎么样解决!!哪位大虾一起帮忙解决一下谢谢
      

  9.   

    你怎么一会jb7,一会jb8的呀,你的错误应该是http://localhost:7001/loginServlet中的路径设置有错,在配置文件中找找是不是路径打错了。
      

  10.   

    Wkenny(小凳子) :
    按照你的改了,还是不对。这个问题是不是就只和web.xml,application.xml,调用servlet的jsp,和这个servlet本身有关啊?还和别的文件或设置相关吗?