有无师傅知道为什么loginservlet类、登录页欢迎页写好后使用浏览器运行时无法跳转到欢迎页:
代码依据书上所给的敲上去,没有显示报错,制作的用户注册界面、登录界面都能成功运行
但是登录界面输入密码和用户名后却显示404不管正确还是错误都是404
以下是三个界面的代码
loginservlet:
package cn.itcast.cha1.response;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
@WebServlet(name = "LoginServlet", urlPatterns = "/LoginServlet")
public class LoginServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charest=utf-8");
String username = request.getParameter("username");
String password = request.getParameter("password");
if (("itcast").equals(username)&&("123").equals(password)){
String contextPath = request.getContextPath();
response.sendRedirect("welcome.html");
}else {
response.sendRedirect("login.html");
}
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request,response);
}
}
**welcome:**
```javascript
<!DOCTYPE html>
<head>
<meta charset="UTF-8"; http-equiv="content-type"; content="text/html">
<title>登录成功</title>
</head>
<body>
欢迎您,登陆成功!
</body>
</html>
**login:**
```javascript
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"; http-equiv="content-type"; content="text/html">
<title>用户登录</title>
</head>
<body>
<!--把表单内容提交到loginServelt-->
<form action="/cha1/LoginServlet" method="post">
用户名: <input type="text" name="username"/><br />
密 码:<input type="password" name="password"><br />
<input type="submit" value="登录" />
</form>
</body>
</html>
以上代码idea并没有显示报错,询问了ai并尝试修改代码发现也没有用。想问问是哪个地方出错了,求指点