JSP两个动作(include,forward)

include动作

 

<div id="container">
 <jsp:include page="HelloWorld.jsp" flush="true|false">
 <jsp:param value="xiaoming" name="username"/>
 </jsp:include>
</div>

 

flush默认值为false

 

Forward动作

跳转页面 forward.jsp

 

<jsp:forward page="another.jsp?username=xiaoming">
 <jsp:param value="18" name="age"/>
 </jsp:forward>

 

接受页面 another.jsp

 

<h1>Hello World!
<%= request.getParameter("username")%>
<br>
age is:
<%= request.getParameter("age")%>
</h1>

 

 

跳转页面:forward.jsp

<jsp:forward page="sayHello.jsp">
       <jsp:param name="user" value="world"/>
       <jsp:param name="user" value="George"/>
</jsp:forward>

 

sayhello.jsp

<%@page import="java.util.*"%>
<html>
  <head><title>Say Hello</title></head>
<body>
<h2><center>Hello, <%=request.getParameter("user")%><br/>
The values of parameter user are : 
<%
        String[] values = request.getParameterValues("user");
        for(int i = 0; i < values.length; i++){
%>
        <%=values[i]%>
<%}%>
</center></h2>
</body>
</html>

 

posted @ 2014-09-16 21:25  马赛克都挡不住  阅读(246)  评论(0编辑  收藏  举报