码迷,mamicode.com
首页 > Web开发 > 详细

jsp页面的跳转方法另类总结

时间:2015-02-16 20:58:09      阅读:185      评论:0      收藏:0      [点我收藏+]

标签:

在Jsp页面中除了可以使用超链接跳转页面以外,还可以使用表单的方法跳转页面,例如下面的例子,test2页面跳转到test1页面:

test2.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%>">

<title>跳转页面使用表单跳转到test1</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>这里的页面是测试跳转到test2
<form action="test1.jsp" method="post">
<input type="submit" value="跳转">
</form>
</body>
</html>

下面的是test1.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%>">

<title>My JSP ‘test1.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">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

</head>

<body>
This is my JSP page. <br>
</body>
</html>

访问test2.jsp页面之后,点击跳转,即可跳转到test1.jsp页面,效果和html的超链接标签差不多<a href="url"></a>

 

jsp页面的跳转方法另类总结

标签:

原文地址:http://www.cnblogs.com/listentothecloud20150215/p/4294489.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!