码迷,mamicode.com
首页 > 其他好文 > 详细

Struts2默认Action

时间:2016-07-25 17:55:36      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:

默认Action,所有未找到路径显示error.jsp页面。

<default-action-ref name="index"></default-action-ref>
<action name="index">
   <result>/error.jsp</result>
</action>

 

package com.action;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.util.ServletContextAware;
import com.opensymphony.xwork2.ActionSupport;

public class HelloWord extends ActionSupport implements ServletRequestAware, ServletResponseAware,ServletContextAware{

    public String add(){
        return "add";
    }
    
    public String update(){
        return "update";
    }
    
    @Override
    public String execute() throws Exception{
        System.out.println("执行action");
        return SUCCESS;
    }

    @Override
    public void setServletResponse(HttpServletResponse response) {
        // TODO Auto-generated method stub
        
    }

    @Override
    public void setServletRequest(HttpServletRequest request) {
        // TODO Auto-generated method stub
        
    }

    @Override
    public void setServletContext(ServletContext context) {
        // TODO Auto-generated method stub
        
    }
}

struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
    "http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>
    <package name="default" namespace="/" extends="struts-default">
        <default-action-ref name="index"></default-action-ref>
        <action name="index">
            <result>/error.jsp</result>
        </action>
      
        <action name="helloword_*" method="{1}" class="com.action.HelloWord">
            <result>/result.jsp</result>
            <result name="add">/{1}.jsp</result>
            <result name="update">/{1}.jsp</result>
        </action>
    </package>
    <constant name="struts.enable.DynamicMethodInvocation" value="false"></constant>
</struts>

 

Struts2默认Action

标签:

原文地址:http://www.cnblogs.com/smilelily/p/5704208.html

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