weixin_46864884 2021-03-26 10:02 采纳率: 0%
浏览 87
已结题

表单经过servlet验证码程序登录成功后,跳转的jsp页面显示的用户名为什么是null?

登陆界面:newinput.jsp
我点这个图片验证码也不会更新!!
<html>
  <head>
    <title>验证码</title>
    <script type="text/javascript">
        $(function(){

            //给验证码的图片,绑定单击事件
            $("#code_img").click(function(){
                alert(this.src);
                //this.src = "${basePath}/kaptcha.jpg?d=" + new Date();
            });

        });

    </script>
  </head>
  <body >
    <FORM action="http://localhost:8080/tmp_war_exploded/newInputServlet" method=get name=form>
      <P>请输入下列信息:<br/>
        学号:<input type="text" name="ID" value="123456"><br/>
        姓名:<input type="text" name="username" value="liu"><br/>
        专业:<input type="radio" name="major" value="计算机"/>计算机
             <input type="radio" name="major" value="软件工程"/>软件工程
             <input type="radio" name="major" value="网络工程"/>网络工程<br/>
        验证码:<input type="text" style= "width: 60px;" name= "code">
              <img id="code_img" src="kaptcha.jpg" alt="" style= "width: 100px; height: 28px;"><br/>

        <input type="submit" value="登录" name="logIn">
    </FORM>
  </body>
</html>

 

验证码servlet:

public class NewInputServlet extends HttpServlet{
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取Session中的验证码
        String token = (String) req.getSession().getAttribute(KAPTCHA_SESSION_KEY);
        //删除Session验证码
        req.getSession().removeAttribute(KAPTCHA_SESSION_KEY);

        String code = req.getParameter("code");

        //获取用户名
        //String username = req.getParameter("username");


        if (token != null && token.equalsIgnoreCase(code)) {
            //System.out.println("该生的姓名为:"+username);

            resp.sendRedirect(req.getContextPath()+"/ok.jsp");
        }else{
            resp.sendRedirect(req.getContextPath()+"/fault.jsp");
        }

    }
}

登录成功后显示:

<body >
<a href="http://localhost:8080/tmp_war_exploded/newinput.jsp">返回登录界面</a> <%  request.setCharacterEncoding("utf-8");

  String yourID=request.getParameter("ID");
  String yourName=request.getParameter("username");
  String yourMajor=request.getParameter("major");

  out.println("<P> 您的姓名:"+yourName+"</P>");
  out.println("<P> 您的学号:"+yourID+"</P>");
  out.println("<P> 您的专业:"+yourMajor+"</P>");

%>

</body>

  • 写回答

1条回答 默认 最新

  • weixin_46864884 2021-03-26 10:03
    关注

    SOS!到底为什么呀!!!!

    评论

报告相同问题?

悬赏问题

  • ¥15 求高通平台Softsim调试经验
  • ¥15 canal如何实现将mysql多张表(月表)采集入库到目标表中(一张表)?
  • ¥15 wpf ScrollViewer实现冻结左侧宽度w范围内的视图
  • ¥15 栅极驱动低侧烧毁MOSFET
  • ¥30 写segy数据时出错3
  • ¥100 linux下qt运行QCefView demo报错
  • ¥50 F1C100S下的红外解码IR_RX驱动问题
  • ¥20 基于matlab的航迹融合 航迹关联 航迹插补
  • ¥15 用Matlab实现图中的光线追迹
  • ¥15 联想笔记本开机出现系统更新界面