jsp response.sendRedirect()用法詳解
sendRedirect()
response和request一樣都是jsp內(nèi)置對(duì)象,request是獲取用戶的請(qǐng)求,response處理用戶請(qǐng)求。sendRedirect()函數(shù)的作用是重定向網(wǎng)頁(yè),向?yàn)g覽器發(fā)送一個(gè)特殊的Header,然后由瀏覽器來(lái)做重定向,轉(zhuǎn)到指定的頁(yè)面。下面我將創(chuàng)建四個(gè)頁(yè)面,首先是sex.jsp,有一個(gè)下拉列表和提交按鈕確定,選擇“男”,就跳轉(zhuǎn)到male.jsp,選擇“女”就跳轉(zhuǎn)到female.jsp,中間通過(guò)sex_action.jsp進(jìn)行重定向
<!-- sex.jsp --> <%@ 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%>" rel="external nofollow" rel="external nofollow" > <title>Sex Select's 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"> </head> <body> <form action="<%=basePath%>c03/sex_action.jsp" method="post"> <select name="sex"> <option>男</option> <option>女</option> </select> <button type="submit">提交</button> </form> </body> </html>
<!-- sex_action.jsp -->
<%@ 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%>" rel="external nofollow"  rel="external nofollow" >
<title>My JSP 'sex_action.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">
</head>
<body>
	<% 
    	request.setCharacterEncoding("UTF-8");
    	String sex = request.getParameter("sex");
    	out.println(sex);
    	if("男".equals(sex)) {
    		response.sendRedirect("male.jsp");
    		return;
    	}
    	else if("女".equals(sex)) {
    		response.sendRedirect("female.jsp");
    		return;
    	}
    %>
</body>
</html>
到此這篇關(guān)于jsp response.sendRedirect()用法詳解的文章就介紹到這了,更多相關(guān)jsp response.sendRedirect()內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
 jsp導(dǎo)出身份證到excel時(shí)候格式不對(duì)但以X結(jié)尾的卻可以
excel導(dǎo)出身份證的時(shí)候顯示有的對(duì)有的不對(duì),身份證以X結(jié)尾的可以,其它都顯示不正確,關(guān)于這個(gè)問(wèn)題的解決方法如下,需要的朋友可以參考下2014-10-10
 jsp頁(yè)面顯示數(shù)據(jù)庫(kù)的數(shù)據(jù)信息表
本文主要介紹了jsp頁(yè)面顯示數(shù)據(jù)庫(kù)的數(shù)據(jù)信息表的實(shí)現(xiàn)方法。具有一定的參考價(jià)值,下面跟著小編一起來(lái)看下吧2017-01-01
 JSP使用Servlet過(guò)濾器進(jìn)行身份驗(yàn)證的方法
這篇文章主要介紹了JSP使用Servlet過(guò)濾器進(jìn)行身份驗(yàn)證的方法,結(jié)合實(shí)例形式分析了Servlet過(guò)濾器的實(shí)現(xiàn)方法及jsp身份驗(yàn)證的具體使用技巧,需要的朋友可以參考下2015-12-12
 SSH整合中 hibernate托管給Spring得到SessionFactory
Spring文件中的 SessionFactory中 加入為了能得到同一個(gè)Session2009-06-06
 Struts2 OGNL調(diào)用公共靜態(tài)方法詳細(xì)介紹
這篇文章主要介紹了Struts2 OGNL調(diào)用公共靜態(tài)方法詳細(xì)介紹的相關(guān)資料,需要的朋友可以參考下2017-01-01

