`
crabdave
  • 浏览: 1295072 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

new ActionForward和mapping.findForward(请求重定向和转发)

阅读更多

new ActionForward和mapping.findForward(请求重定向和转发)

 

1.struts 中return new ActionForward(URI,true) 与 <forward name = "/success" path = "/page/success.jsp"/>。
1. 在ACTION里 使用
String URI = "";       
return new ActionForward(URI,true);的组合,一般是因为需要在request中加入 parameter ,但如果此时在这个action里试图加入 Attribute,则转向的页面将接收不到 Attribute的值。


2.   使用return new ActionForward(mapping.findForward("/success"));

表示已经在struts的action-config.xml中配置了success的转向,如<forward name = "/success" path = "/page/success.jsp"/>。

补充:
ActionForward类提供了下面五种构造器:

      public ActionForward()
  public ActionForward(String path) 常用
  public ActionForward(String path, boolean redirect)
  public ActionForward(String name, String path, boolean redirect)
  public ActionForward(String name, String path, boolean redirect, boolean contextRelative) 

       

  虽然这些构造器是不需要说明的,但我们应该注意下面几点。在这些构造器中,第二种可能是最常用的。
后四种构造器中的path参数表示的是到目的资源的路径。
后三种构造器中的redirect布尔值表示的是是否执行了一个重定向(redirect)。(缺省情况下,这个值设置为false,因为redirect比forward慢。)
最后,第五个构造器中的contextRelative布尔值表示该路径是否应该是context-relative的,而不是module-relative的。

如  

 return (new ActionForward("/mainMenu.jsp"));
 return (new ActionForward("/login.jsp")); 

 
 

分享到:
评论

相关推荐

    java+jsp上传文件

    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException { if (!ServletFileUpload.isMultipartContent(request...

    struts1.3页面跳转问题

    ActionForward forward = mapping.findForward("success"); return forward; ``` 其中,"success"是在struts-config.xml中预先定义的forward节点名,对应要转发到的JSP页面。 ```xml &lt;action path="/login" ...

    struts_跳转演示

    - ActionForward:在Struts中,用于表示请求转发的目标,可以是另一个Action或者一个JSP页面。 - RequestDispatcher:Servlet API中的一个接口,用于实际的请求转发或重定向操作。 5. **跳转类型** - 请求转发...

    上传到服务器例子[用struts_MVC]

    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { if (!ServletFileUpload.isMultipartContent(request)) ...

    strut深入的学习

    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { LoginForm loginForm = (LoginForm) form; String ...

    java练习之XML读取

    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // 业务逻辑处理 boolean success = true; if ...

    J2EE实例,strut实现登录

    ActionForward定义了请求的转发路径,可以是相对路径或绝对路径。在`struts-config.xml`中,我们可以这样配置: ```xml &lt;action path="/login" type="com.example.LoginAction" name="loginForm"&gt; &lt;forward name=...

    java 文件上传 SmartUpload.pdf SmartUpload.jar包

    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { SmartUpload smartUpload = new ...

    testRedirect:在struts中测试登录的redirect,transmit

    ActionForward forward = mapping.findForward("success"); response.sendRedirect(forward.getPath()); ``` 这将把用户重定向到"success"对应的页面。 2. **转发(Forward)** 转发则是服务器内部操作,不会...

    使用Spring , ActionSupport ,struts1整合实例

    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // 获取表单数据 String username = form....

    JSP文件上传功能(struts)

    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException { try { CommonsMultipartRequestHandler handler = ...

    Struct登录

    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { LoginForm loginForm = (LoginForm) form; String ...

    struts,hibernate,spring集成开发示例.doc

    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String username = request.getParameter("username");...

    java urlrewrite解决默认页问题

    public ActionForward index(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { EntryinfForm vo = (EntryinfForm) form; try { return mapping....

    struts深入理解

    通过上述内容,我们可以了解到Struts框架是如何通过`ActionServlet`、`Action`、`ActionForm`、`ActionForward`和`ActionMapping`等核心组件来实现MVC设计模式的。这为开发人员提供了清晰的架构思路,有助于构建可...

    struts文件上传例子

    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException { UploadForm uploadForm = (UploadForm) form; // 假设...

    伪静态URLRewrite实例解析

    - `&lt;to&gt;` 指定实际处理请求的路径,支持转发(forward)和重定向(redirect)两种方式。 - `$1` 表示正则表达式中第一个括号内的匹配结果,即捕获的数字。 **4. Action处理类** 创建一个名为`ProcessAction`的处理类,...

    基于Struts技术的购物车的实现

    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { ShoppingCart cart = (ShoppingCart) request.getSession().getAttribute(...

    struts1配置的demo

    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // 业务逻辑处理,如从数据库获取电影信息 // ... /...

    struts1实现文件上传和下载

    public ActionForward downloadFile(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String filePath = "D:\\loadfile\\temp\\yourfile....

Global site tag (gtag.js) - Google Analytics