码迷,mamicode.com
首页 > Web开发 > 详细

jsp一个小问题

时间:2019-07-16 14:04:15      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:att   type   setattr   intel   post   lan   log   for   错误   

刚才使用request.getAttribute();时候无法获取到值,一直为null,经过分析,得到下面的

index1.jsp

<%--
  Created by IntelliJ IDEA.
  User: 亦清
  Date: 2019/7/16
  Time: 12:56
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>用户登录索引</title>
</head>
<body>
<%
    try{
        int money=100;
        int b=0;
        request.setAttribute("result",money/0);
    }catch (Exception e){
        request.setAttribute("result","页面出现错误");
    }
%>
    <jsp:forward page="login.jsp"/>
<%--<a href="login.jsp?name=321&password=qqqq">跳转界面</a>--%>
</body>
</html>

login.jsp

<%--
  Created by IntelliJ IDEA.
  User: 亦清
  Date: 2019/7/16
  Time: 12:56
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String name = request.getParameter("name");
    String password = request.getParameter("password");
%>
<html>
<head>
    <title>登陆</title>
</head>
<body>
<%    String result = (String)request.getAttribute("result");
%>
<%=result%>
<form name="form1" action="" method="post">
    用户名 <input type="text" name="name" style="width:120px" value="<%=name%>"><br>&nbsp;&nbsp;&nbsp;码 <input type="password" name="password" value="<%=password%>" style="width:120px"><br>
    <input type="submit" value="提交">
</form>
</body>
</html>

1.第一个request.setAttribute();的jsp片段所放的位置必须和login.jsp当中一样,就是要放在body标签就都放在body里面,不然会得到Nul,

2.index.jsp一旦点击a标签跳转到login.jsp,也会获取到null,

很奇怪,暂时放着

jsp一个小问题

标签:att   type   setattr   intel   post   lan   log   for   错误   

原文地址:https://www.cnblogs.com/eenio/p/11194410.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!