为什么一直跳转登陆失败啊,

来源:4-11 阶段案例——实现用户登录

qq__夏末_04163973

2016-10-24 20:11

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

<%

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

  <head>

    <base href="<%=basePath%>">

    

    <title>My JSP 'login.jsp' starting page</title>

    

<meta http-equiv="pragma" content="no-cache">

<meta http-equiv="cache-control" content="no-cache">

<meta http-equiv="expires" content="0">    

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">

<meta http-equiv="description" content="This is my page">

<!--

<link rel="stylesheet" type="text/css" href="styles.css">

-->


  </head>

  

   <body>

    <div>

  <form action="dologin.jsp" method="post">

      <label>用户: </label>

  <input name="username" value=""/>

      <label>密码: </label>

  <input type="password" name="password"/>

  <input type="submit" value="登录"/>

  

  </form>

  

  </div>

   

  </body>

</html>



<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

<%

 String path = request.getContextPath();

 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

 String username="";

 String password="";

 request.setCharacterEncoding("utf-8");//防止中文乱码

 username=request.getParameter("username");

 password=request.getParameter("password");

 

 

 if("123".equals("username")&&"123".equals("password"))

 {

   request.getRequestDispatcher("login_success.jsp").forward(request,response);

 }

 else

 {

   response.sendRedirect("login_failure.jsp");

 }

%>


<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

<%

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

  <head>

    <base href="<%=basePath%>">

    

    <title>My JSP 'login_success.jsp' starting page</title>

    

<meta http-equiv="pragma" content="no-cache">

<meta http-equiv="cache-control" content="no-cache">

<meta http-equiv="expires" content="0">    

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">

<meta http-equiv="description" content="This is my page">

<!--

<link rel="stylesheet" type="text/css" href="styles.css">

-->


  </head>

  

  <body>

      登录成功 <br>

  </body>

</html>



<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

<%

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

  <head>

    <base href="<%=basePath%>">

    

    <title>My JSP 'login_failure.jsp' starting page</title>

    

<meta http-equiv="pragma" content="no-cache">

<meta http-equiv="cache-control" content="no-cache">

<meta http-equiv="expires" content="0">    

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">

<meta http-equiv="description" content="This is my page">

<!--

<link rel="stylesheet" type="text/css" href="styles.css">

-->


  </head>

  

  <body>

      登录失败 <br>

  </body>

</html>


写回答 关注

1回答

  • 慕用7772223
    2016-10-24 22:35:31
    已采纳

    如果是404错位,那就是你的跳转路径填写错误,如果是500,那就看看你代码哪里写错了,而且还没报错


    qq__夏末...

    非常感谢!

    2016-10-25 19:30:50

    共 1 条回复 >

JAVA遇见HTML——JSP篇

Java Web入门级教程JSP,带你轻松的学习JSP基础知识

248277 学习 · 3071 问题

查看课程

相似问题