易截截图软件、单文件、免安装、纯绿色、仅160KB

JSP跳转的几种方式|Struts动态跳转

String url="http://www.baidu.com";
   ActionForward gotourl = new ActionForward(url);
   gotourl.setPath(url);
   gotourl.setRedirect(true);
   return gotourl;
  1.RequestDispatcher.forward()
   是在服务器端起作用,当使用forward()时,Servlet engine传递HTTP请求从当前的Servlet or JSP到另外一个Servlet,JSP 或普通HTML文件,也即你的form提交至a.jsp,在a.jsp用到了forward()重定向至b.jsp,此时form提交的所有信息在 b.jsp都可以获得,参数自动传递.
  但forward()无法重定向至有frame的jsp文件,可以重定向至有frame的html文件,同时forward()无法在后面带参数传递,比如servlet?name=frank,这样不行,可以程序内通过response.setAttribute("name",name)来传至下一个页面.
  重定向后浏览器地址栏URL不变.
  例:在servlet中进行重定向
 
Java代码
public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException   
{   
  response.setContentType("text/html; charset=gb2312");   
  ServletContext sc = getServletContext();   
  RequestDispatcher rd = null;   
  rd = sc.getRequestDispatcher("/index.jsp"); //定向的页面   
  rd.forward(request, response);   
}  
public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
{
  response.setContentType("text/html; charset=gb2312");
  ServletContext sc = getServletContext();
  RequestDispatcher rd = null;
  rd = sc.getRequestDispatcher("/index.jsp"); //定向的页面
  rd.forward(request, response);
}
 
  通常在servlet中使用,不在jsp中使用。
 
       2.response.sendRedirect()
  是在用户的浏览器端工作,sendRedirect()可以带参数传递,比如servlet?name=frank传至下个页面,同时它可以重定向至不同的主机上,sendRedirect()可以重定向有frame.的jsp文件.
  重定向后在浏览器地


相关文档:

jsp乱码解决大全(转自csdn一高手)

jsp中文显示乱码解决方案
一、JSP页面显示乱码
二、表单提交中文时出现乱码
三、数据库连接
大家在JSP的开发过程中,经常出现中文乱码的问题,可能一至困扰着您,我现在把我在JSP开发中遇到
的中文乱码的问题及解决办法写出来供大家参考。
一、JSP页面显示乱码
下面的显示页面(display.jsp)就出现乱码:
< ......

组拼jsp方法

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> ......

组拼jsp方法2

<html:html>
<HEAD>
<tiles:insert attribute="header" />
</HEAD>
<body>
<tiles:insert attribute="top" />
<table width="100%" height="400" border="0" align="center"
 cellpadding="0" cellspacing="0">
 <tr>
  <td width="178" ......

组拼jsp方法3

<table width=100% border="0" align="center" cellpadding="0"
 cellspacing="0">
 <tr>
  <td height="1" class="gray1"></td>
 </tr>
</table>
<tiles:insert attribute="footer" />
</body>
</html:html> ......

组拼jsp方法4

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tiles-definitions PUBLIC
  "-//Apache Software Foundation//DTD Tiles Configuration//EN"
  "http://jakarta.apache.org/struts/dtds/tiles-config.dtd">
<tiles-definitions>
 <definition name="tscs.templet" path="/pa ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号