实现从demo4.jsp带数据<username,admin>到shopList.jsp中,通过request。getParameter(“username”)进行获取到了。这就是从一个jsp到另外一个jsp如何带数据故去,以后就可以这样用了。
demo4.jsp:
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8" isELIgnored="false"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String context = request.getContextPath();// /dt41_javaweb2
String path = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+context+"/";
%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=path %>">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>jsp内置标签</title>
</head>
<body>
<!-- forward标签,可以实现跳转
“/”:服务器地址+工程名。 jsp可以跳jsp,jsp可以跳servlet,servlet可以跳jsp
-->
<%-- <jsp:forward page="/FrontServlet"></jsp:forward> --%>
<%-- <jsp:forward page="/shopList.jsp"></jsp:forward> --%>
<jsp:forward page="/shopList.jsp">
<jsp:param value="admin" name="username"/>
</jsp:forward>
</body>
</html>
上面倒数第三行中:
<jsp:forward page="/shopList.jsp">
<jsp:param value=“admin” name=“username”/>现在发现了,name和value是一个类似于键值对的东西,类似<key,value>,然后想要取admin参数的时候其实的.getParameter(username)。
</jsp:forward>
shopList.jsp:
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%
String context = request.getContextPath();// /dt41_javaweb2
String path = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+context;
%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=path %>">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>商品列表</title>
</head>
<body>
<center>
<form action="<%=path %>/HistoryServlet" method="get">
<input type="checkbox" name="goods" value="1">洗衣机
<input type="checkbox" name="goods" value="2">冰箱
<input type="checkbox" name="goods" value="3">空调
<input type="checkbox" name="goods" value="4">娃娃
<!-- <input type="text" name="username"> -->
<input type="submit" value="商品浏览">
</form>
</center>
<%
String username=(String)request.getParameter("username");
System.out.println(username);
%>
</body>
</html>
看这里倒数几行,
<%
String username=(String)request.getParameter(“username”);
System.out.println(username);
%>
版权声明:本文为Jenny_xuexi原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。