首页 > Web开发 > 详细

JSP_<jsp:forward>应用

时间:2014-05-18 07:01:58      阅读:439      评论:0      收藏:0      [点我收藏+]

本文出自:http://blog.csdn.net/svitter


实验环境:Myeclipse10 + tomcat7

简单应用于登陆界面。jsp:forward的作用是,把当前的JSP页引导到另一个页面上,浏览器地址本显示的是当前网页的地址,内容则是另一个界面的。

1.User.html

<!DOCTYPE html>
<html>
<head>
<title>登陆信息</title>

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">

<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->

</head>

<body>
	<form action="Login.jsp" method="post" name="Loginfrm" id="Loginform">
		<table width="298" border="0" align="center" cellpadding="2" cellspacing="1">
			<tr>
				<td align="right">用户名:</td>
				<td align="left"><input name="User" type="text" size="30">
				</td>
			</tr>
			<tr>
				<td align="right">密码:</td>
				<td align="left"><input name="Password" type="password"
					size="30">
				</td>
			</tr>
			<tr>
				<td colspan="2" align="center"><input type="submit" value="login">
				 
				<input type="reset" value="reset"></td>
		</table>
	</form>
</body>
</html>

2.Login.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>用户登陆</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>
    <% 
    String User=request.getParameter("User");
    String Password=request.getParameter("Password");
    if(User.equals("Admin") && Password.equals("Admin")){%>
    	<jsp:forward page="welcome.jsp"/>
	<%} else { %>
		<jsp:forward page="errorPage.jsp"/>
	<%} %>
  </body>
</html>

3.errorPage.jsp; 注意isErrorPage=TRUE;

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" isErrorPage="true"%>
<%
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>错误处理页面</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>
    <h1>错误信息</h1>
    <hr><center>
    <h3><%=exception%>
    </h3>
    </center>
  </body>
</html>
4.welcome.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 ‘welcome.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>
    Welcome!<br>
  </body>
</html>

对应资源下载:http://download.csdn.net/detail/svitter/7358523

JSP_<jsp:forward>应用,布布扣,bubuko.com

JSP_<jsp:forward>应用

原文:http://blog.csdn.net/svitter/article/details/26009333

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!