求问javaweb的关于servlet的问题

我写了个登陆页面,也写了登陆的servlet,但是测试的时候根本没有运行post方法
请大佬帮我看看怎么回事
代码如下
login.jsp

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8" isELIgnored="false"%>
<!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=utf-8">
<title>Insert title here</title>
</head>
<body>
    <center>
        <h1 style="color:red">登陆</h1>
            <form id="login" name="login" action="Servlet/LoginServlet" method="post">
                <table border="0">
                    <tr>
                        <td>账号:</td>
                        <td><input type="text" name="username"></td>
                    </tr>
                         <tr>
                            <td>密码:</td>
                            <td><input type="password" name="password">
                        </td>
                    </tr>
                </table>
                  <select  id="type" name="type">
                    <option value="1">玩家</option>
                    <option value="2">店家</option>
                    <option value="3">管理员</option>
                </select>
                    <br>
                <input type="submit" value="登录" style="color:#BC8F8F">
            </form>
            <form action="regist.jsp">
                <input type="submit" value="注册" style="color:#BC8F8F">  
            </form>
    </center>
</body>
</html>

LoginServlet

package Servlet;

import java.io.IOException;
import java.sql.Connection;

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

import DB.DBConnection;

/**
 * Servlet implementation class LoginServlet
 */
@WebServlet("/LoginServlet")
public class LoginServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public LoginServlet() {
        super();
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        this.doPost(request, response);
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        System.out.println("进入post方法");
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        String type = request.getParameter("type");
        System.out.println(username+"--"+password);


    }

}

如上,我在post方法里写了打印语句,结果测试根本没有输出任何东西

1个回答

路径出错了吧,jsp那边跳转的servlet路径,把前面的Servlet去掉试试

hqd66
朝目标努力的苍白 回复jay705: 哦哦,原来这个注解是路径的意思啊,我以为只是个命名
5 个月之前 回复
jay705
jay705 回复朝目标努力的苍白: 访问路径用的是@WebServlet("/LoginServlet")这个,你改这个为Servlet/LoginServlet也是一样的道理
6 个月之前 回复
hqd66
朝目标努力的苍白 哇成功了!!!谢谢大佬!!顺便问下为什么加上Servlet就不行呢,明明LoginServlet在Servlet这个文件夹下的
6 个月之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!