Murphyzzzzzz
2019-05-18 23:21
采纳率: 75%
浏览 483
已采纳

jsp中form中提交 但是request获取不到!!!为什么,大佬帮看

为了完成老师给的简单的jsp模拟登录,利用jsp:forward实现
index.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title>$Title$</title>
  </head>
  <body>
  <h1>模拟登陆</h1>
  <form action="forward.jsp">
  <input type="text",name = "id" id = "id">账号<br>
  <input type="password",name = "pwq" id = "pwq">密码<br>
    <input type="submit" value="登录">
  </form>
  </body>
</html>

在forward中尝试判断 ,密码是否正确,可是却一直获取不到,打印输出是null???为什么 哪里写错了

forward.jsp

<%--
  Created by IntelliJ IDEA.
  User: Murphy
  Date: 2019-05-18
  Time: 21:57
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String inId = request.getParameter("id");
    String inPwd = request.getParameter("pwq");
%>
<%= inId%>
<%= inPwd%>

<%
    String rightId = "123";
    String rightpwd = "123";
    String access ;
    if(inId == rightId && inPwd == rightpwd)
    {
        access = "登录成功";
        out.print("Yes");
    }else{
        access = "You are not login";
    }
%>

<%= access%>

<%
    if(access == "登录成功"){ %>

<jsp:forward page="homepage.jsp">
    <jsp:param  value="<% =accsess %>" name="access" />
</jsp:forward>
 <% } else{ %>
alert("密码错误!")
 <% response.sendRedirect("index.jsp"); %>
<% }%>

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

4条回答 默认 最新

  • threenewbee 2019-05-19 09:25
    最佳回答
      <input type="text",name = "id" id = "id">账号<br>
      <input type="password",name = "pwq" id = "pwq">密码<br>
        ->
          <input type="text" name = "id"  id = "id">账号<br>
      <input type="password" name = "pwq"  id = "pwq">密码<br>
    

    if(inId == rightId && inPwd == rightpwd)
    这里要用equals而不是==比较

    评论
    解决 无用
    打赏 举报
查看更多回答(3条)

相关推荐 更多相似问题