首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

JSP顶用form传值奇怪的为null

2013-07-04 
JSP中用form传值奇怪的为null1.jsp%@ page languagejava importjava.util.* pageEncodingISO-885

JSP中用form传值奇怪的为null
1.jsp


<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
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 '1.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>
    <form action="/Homework4/2.jsp" method="post">
    <input type="text" name="tt" /><br>
    <input type="submit" value="fuckyou"/>
    </form>
  </body>
</html>


2.jsp

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
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 '2.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 str = "";
    Enumeration e =  request.getAttributeNames();
    while (e.hasMoreElements())
    str = str + (String)e.nextElement();
    System.out.println(str);
    */
    String tt = (String)request.getAttribute("tt");
    out.println(tt);
    out.flush();
    %>
  </body>
</html>


在2.jsp页面只有null JSP form


[解决办法]
String tt=request.getParameter("tt")
[解决办法]
页面中传过来的值需要用request.getParameter("tt");获取

热点排行