JSP_<jsp:forward>应用

本文出自: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

时间: 2024-08-09 01:17:53

JSP_<jsp:forward>应用的相关文章

jsp跳转标签&lt;jsp:forward&gt;

forward.jsp <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd&qu

用&lt;jsp:include&gt;或&lt;jsp:forward&gt;动作标签与&lt;jsp:param&gt;搭配使用时出现的乱码问题

解决方案:在原请求也加入request.setCharacterEncoding("gb2312"); 例子1: <% request.setCharacterEncoding("gb2312"); %> <jsp:include page="content.jsp"> <jsp:param name="param" value="哈哈哈"></jsp:param&

JSP_&lt;jsp:application&gt;实例

本文出自:http://blog.csdn.net/svitter 实验环境:Myeclipse10 + tomcat7 Application对象为了多个应用程序保存信息,对于每个容器,每个用户都共同拥有一个application对象,服务器启动以后,会自动创建一个application对象,这个对象会一直保持到服务器关闭. 下列实例用于统计页面访问次数. 1.application.jsp <%@ page language="java" import="java.

Struts2中&lt;jsp:forward page=&quot;xxx.action&quot;&gt;&lt;/jsp:forward&gt;失效

问题:在Struts2中<jsp:forward page="xxx.action"></jsp:forward>失效了,不但调转不过去还报404错误.不知道是Struts2中不支持还是需要其他的配置. 原因:因为struts2采用过滤器的方式处理请求,默认情况时监控url地址的变化 解决办法1.配置web.xml 解决 [html] view plaincopyprint? <filter-mapping> <filter-name>s

Struts2.x jsp页面无法使用jsp:forward跳转到action

问题:使用<jsp:forward page="test"></jsp:forward>语句无法跳转到test所对应的action. 解决办法:在web.xml中 添加 <filter-mapping>          <filter-name>struts2</filter-name>          <url-pattern>/*</url-pattern>          <dispa

jsp forward 转到springMVC的 controller传值问题

jsp forward 转到springMVC的 controller传值问题 总是404等各种错误 网上查询各种做法 都很曲折 各种尝试只有豁然开朗 1 在JSP页面上面获取传来的各个参数 <jsp:forward page="/product/showList.do"> <jsp:param name="queryType" value="<%= queryType %>" /> <jsp:param

response.sendRedirect()与request.getRequestDispatcher(&quot;/index.jsp&quot;).forward(request, response)两者辨析

知识点轮廓 一 辨析response.sendRedirect()与request.getRequestDispatcher("/index.jsp").forward(request, response) 二 辨析请求转发与重定向异同问题[知识点总结] 第一部分: JSP中response.sendRedirect()与request.getRequestDispatcher().forward(request,response)这两个对象都可以使页面跳转,但是二者是有很大的区别的,

JSP基础语法--跳转指令 jsp:forward page

带参数的跳转指令: <jsp:forward page="{路径|<%=表达式%>}"/> <jsp:param name="参数名称" value="参数内容"/> </jsp:forward> 实际生活中,很多人有email邮箱,如果成功的话,跳转到邮箱的首页,失败的话,重新登录 跳转之后的页面: <%@ page contentType="text/html" pag

jsp - forward指令

forward指令 既可以指向静态的html页面,也可以转发到动态的jsp页面,并可以保留先前请求的参数. 例如,在web中新建一个Jsp_src.jsp的jsp页面: <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = r