国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

jsp response.sendRedirect()用法詳解

瀏覽:171日期:2022-06-08 08:14:24

sendRedirect()

response和request一樣都是jsp內置對象,request是獲取用戶的請求,response處理用戶請求。sendRedirect()函數的作用是重定向網頁,向瀏覽器發送一個特殊的Header,然后由瀏覽器來做重定向,轉到指定的頁面。下面我將創建四個頁面,首先是sex.jsp,有一個下拉列表和提交按鈕確定,選擇“男”,就跳轉到male.jsp,選擇“女”就跳轉到female.jsp,中間通過sex_action.jsp進行重定向

<!-- 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>

到此這篇關于jsp response.sendRedirect()用法詳解的文章就介紹到這了,更多相關jsp response.sendRedirect()內容請搜索以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持!

標簽: JSP
主站蜘蛛池模板: 杭州市| 璧山县| 九寨沟县| 濮阳县| 枣强县| 云霄县| 淅川县| 滦南县| 常州市| 新密市| 武鸣县| 应用必备| 关岭| 余江县| 肥城市| 望城县| 农安县| 华亭县| 高陵县| 湟源县| 永宁县| 宣恩县| 古田县| 五指山市| 田阳县| 桑日县| 县级市| 浦江县| 浦城县| 淮南市| 津南区| 新昌县| 烟台市| 莒南县| 乐昌市| 宁乡县| 阳曲县| 城固县| 确山县| 安塞县| 正定县|