登陆界面,点登陆后直接跳转到404界面了,不是跳转到我指定的界面,怎么解决?

木司冷雨剑 2016-07-07 12:09:43
下面是代码,我没有动那个web.xml
package controller;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import domain.User;
import service.UserService;

public class LoginServlet extends HttpServlet
{
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
doPost(req, resp);
}

protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
String username = req.getParameter("username");
String userpsw = req.getParameter("userpsw");
User user = new User();
user.setUsername(username);
user.setUserpsw(userpsw);
HttpSession session = req.getSession();
String forward = "";
if (UserService.CheckLogin(user))
{
forward = "success.jsp";
session.setAttribute("name", username);
}
else
{
forward = "error.jsp";
}
RequestDispatcher rd = req.getRequestDispatcher(forward);
rd.forward(req, resp);
}

}

<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<html>
<head>
<title>login</title>
</head>
<body>
<form action="login" method="post">
用户名称:<input type="text" name="username" value=""><br>
用户密码:<input type="password" name="userpsw" value=""><br>
<input type="submit" name="submit" value="登陆"> <input
type="reset" name="reset" value="重写">
</form>
</body>
</html>
...全文
2074 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
木司冷雨剑 2016-07-07
  • 打赏
  • 举报
回复
引用 1 楼 twqllq98849577 的回复:
404很明显,跳转的路径不存在
跳转之后的页面我是编写了的, 单独运行那个页面可以出来,但是从登陆界面跳转就报404
twqllq98849577 2016-07-07
  • 打赏
  • 举报
回复
404很明显,跳转的路径不存在
  • 打赏
  • 举报
回复
引用 8 楼 asdfqwzhd 的回复:
[quote=引用 7 楼 qnmdcsdn 的回复:] 你没动web.xml,没在里边配置servlet拦截,怎么会进到servlet中,又怎么会跳转?

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>logintest1</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>     
</web-app>
这是默认给的代码,我这个正确的web.xml应该怎么写?我小白之前没弄过这个web开发。。[/quote]

<filter>
		<filter-name>Servlet</filter-name>
		<filter-class>你的包名加类名</filter-class>
	</filter>
	<filter-mapping>
		<filter-name>Servlet</filter-name>
		<url-pattern>/</url-pattern>
	</filter-mapping>
加到里边
moon__stone888888 2016-07-07
  • 打赏
  • 举报
回复
把浏览器中的URL 报错地址对比一下实际的sucess.jsp地址,应该找得出来。
eznur 2016-07-07
  • 打赏
  • 举报
回复
好像没注册你的servlet啊
木司冷雨剑 2016-07-07
  • 打赏
  • 举报
回复
引用 5 楼 Brain_Storming 的回复:
浏览器中URL地址写错了,或者web.xml中action没有和form表单中的action对应上。 反正404肯定过是路径问题
那web.xml里应该怎么写?我小白之前没弄过这个web开发。。
木司冷雨剑 2016-07-07
  • 打赏
  • 举报
回复
引用 7 楼 qnmdcsdn 的回复:
你没动web.xml,没在里边配置servlet拦截,怎么会进到servlet中,又怎么会跳转?

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>logintest1</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>     
</web-app>
这是默认给的代码,我这个正确的web.xml应该怎么写?我小白之前没弄过这个web开发。。
  • 打赏
  • 举报
回复
你没动web.xml,没在里边配置servlet拦截,怎么会进到servlet中,又怎么会跳转?
xiatianlong丶 2016-07-07
  • 打赏
  • 举报
回复
你看看你要跳转的路径,你再看看你404界面浏览器的地址
Brain_Storming 2016-07-07
  • 打赏
  • 举报
回复
浏览器中URL地址写错了,或者web.xml中action没有和form表单中的action对应上。 反正404肯定过是路径问题
Afaker 2016-07-07
  • 打赏
  • 举报
回复
jsp是放在哪里?
  • 打赏
  • 举报
回复
你就写个success.jsp,也不写个路径,他没找到。给齐纳买加上路径就行了

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧