日期:2014-05-17  浏览次数:20700 次

servlet配置
我有一个LoginConf类
在login.jsp里面要访问它:
<form action="LoginConf" method="post">
如何配置web.xml
以下是我的配置:(LoginConf没有设置包名):
   

    <servlet>
     <servlet-name>LoginConf</servlet-name>
     <servlet-class>LoginConf</servlet-class>
    </servlet>
    <servlet-mapping>
     <servlet-name>LoginConf</servlet-name>
     <url-pattern>/LoginConf</url-pattern>
    </servlet-mapping>

但是当我通过login.jsp访问serlet时页面没有返回结果
login.jsp::

<%@ page language="java" contentType="text/html; charset=gb2312"
    pageEncoding="gb2312"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>用户登录</title>
</head>
<body>
<h2>用户登录</h2>
<form action="LoginConf" method="post">
<table>
    <tr>
        <td>用户名:</td>
        <td><input type="text" name="uname" /></td>
    </tr>
    <tr>
        <td>密&nbsp;&nbsp;码:</td>
        <td><input type="password" name="password" />
    </tr>
    <tr>
        <td colspan="2">
            <input type="submit" value="登录"/>
            <input type="reset" value="重置"/>
        </td>
    </tr>
</table>
</form>
</body>
</html>

而我修改浏览器地址为http://localhost:1228/StructLearning/LoginConf?uname=admin&password=admin时,显示登录成功
以下是LoginConf.java:


import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class LoginConf
 */
@WebServlet(description = "登录检测", urlPatterns = { "/LoginConf" })
public class LoginConf extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
 *      response)
 */
protected void doGet(HttpServletRequ