今天写了一个程序,因为混淆了getParameter和getAttribute的使用,折磨了楼主一个小时。最终发现a标签拼接的数据只能用getParameter获取,不能用getAttribute获取。
区别见博主博客:http://blog.csdn.net/u010003835/article/details/49978623
url: http://localhost:8080/Web_Servlet_JSP_MySql_Tomcat_Demo/jsp/manager_modify_password.jsp?username_m=sky
拼接参数的JSP
<%@page import="com.login.bean.UserObject"%>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
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>管理员界面</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>
<span style="color:red;font-weight:bold">
<%
if(session.getAttribute("login_user")!=null){
out.println("尊敬的"+session.getAttribute("login_user")+"<br/>");
}
%>
</span>
<div>
<a href="jsp/login.jsp">-注销-</a>
<a href="jsp/modify_password.jsp">-修改密码-</a>
</div>
<div>
<div>
<%
if(request.getAttribute("tips")!=null){
out.println(request.getAttribute("tips")+"<br/>");
}
%>
</div>
<form method="post" action="servlet/deleteUser">
<table>
<tr>
<td>序号</td>
<td>用户名</td>
<td>删除</td>
<td>修改密码</td>
</tr>
<!--
<tr>
<td>1</td>
<td>szh</td>
<td><input name="username" type="checkbox"/></td>
<td><input type="checkbox"/></td>
</tr>
-->
<%
List<UserObject> allUserList = (List<UserObject>)request.getAttribute("allUser");
if(!allUserList.isEmpty()){
for(int i=0; i<allUserList.size(); i++){
UserObject temp = allUserList.get(i);
out.print("<tr>");
out.print("<td>"+i+"</td>");
out.print("<td>"+temp.getUser_name()+"</td>");
out.print("<td>"+"<input name=\"username\""+" value="+"\""+temp.getUser_name() +"\"" +" type=\"checkbox\"/>"+"</td>");
out.print("<td>"+"<a href=\"jsp/manager_modify_password.jsp?username_m="+temp.getUser_name()+"\">修改密码</a>"+"</td>");
out.print("</tr>");
}
}
%>
</table>
<input type="submit" value="确认删除"/>
<input type="reset" value="重选">
</form>
</div>
</body>
</html>
接受参数的JSP
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%--request.setCharacterEncoding("utf-8");--%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>管理员修改页</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>
<!-- request.getAttribute("username") -->
<div>
<form method="post" action="">
<input type="text" readonly="readonly" value="<%=request.getParameter("username_m")%>" name="username"/><br/>
<div>新密码</div>
<input type="password" placeholder="请输入新密码" name="new_password"/><br/>
<input type="submit" value="修改"/><input type="reset" value="重填"/><br/>
</form>
</div>
</body>
</html>