为什么我的一直都是进入登录失败界面

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

龙鸣星星

2016-12-15 20:08

我根据老师教的写的代码 但是不管输入的帐号密码是不是admin 都是进入登录失败的页面  可否帮看看那里错了

//login.jsp

<%@ page language="java" import="java.util.*" contentType="text/html; charset=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 'index.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>

   <big><strong><a>用户登录</a></strong></big><hr>

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

   <table>

   <tr>

   <td>用户名</td>

    <td><input type="text" name="usename"/></td>

   </tr>

   <tr>

   <td>密码</td>

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

   </tr>

   <tr>

   <td colspan="2"><input type="submit" value="登录"/></td>

   </tr>

   </table>

   </form>

  </body>

</html>

//dologin.jsp

<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8" %>

<%

String path = request.getContextPath();

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

String usename="";

String password="";

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

usename=request.getParameter("usename");

password=request.getParameter("password");

//如果用户名和密码都是admin则登录成功否则失败

if("admin".equals(usename)&&"admin".equals(password))

{   

     session.setAttribute("loginuesname",usename );

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

    

     }

     else

     {

     response.sendRedirect("login_failure.jsp");

     }


%>

//login_success.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>

  <%

    String loginusename="";

    if(session.getAttribute("loginusename")!=null)

    {

       loginusename=session.getAttribute("loginusename").toString();

       }

   %>

   欢迎您<font color="red"><%=loginusename%></font>登录成功.

  </body>

</html>

//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_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>

    <strong>登录失败,请返回重新登录!</strong><br>

    <strong><a href="login.jsp">返回登录</a></strong>

  </body>

</html>


写回答 关注

2回答

  • qq_森旅迷了鹿_0
    2016-12-20 16:41:21

    自己不细心。看图

    5858eeaa0001c47205000190.jpg

    5858eeaa0001d24a05000347.jpg


    qq_森旅迷... 回复龙鸣星星

    不用谢,记得给最佳哦。

    2016-12-21 09:10:42

    共 4 条回复 >

  • javc
    2016-12-15 22:43:57

    什么错误?


    龙鸣星星

    没错误 就是在登录界面 不管密码和帐号是什么都是进入我设置的错误界面

    2016-12-19 19:49:15

    共 1 条回复 >

JAVA遇见HTML——JSP篇

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

248277 学习 · 3071 问题

查看课程

相似问题