读书人

JSP顶用form传值奇怪的为null

发布时间: 2013-07-04 11:45:51 作者: rapoo

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");获取

读书人网 >Java Web开发

热点推荐