清晨

新的开始

导航

修改Action默认执行方法

Posted on 2014-06-22 13:57  gdds  阅读(539)  评论(0)    收藏  举报

创建action,内容如下:

package action;

 

import com.opensymphony.xwork2.ActionSupport;

 

public class A extends ActionSupport {

    public String toJsp(){

       return "success";

    }

}

配置struts.xml文件

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE struts PUBLIC

    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"

    "http://struts.apache.org/dtds/struts-2.0.dtd">

 

<struts>

    <package name="default" namespace="/" extends="struts-default">

         <action name="A" class="action.A" method="toJsp">

            <result>/hello.jsp</result>

         </action>

         <!--action默认执行的方法是execute,通过method可以修改action执行的方法 -->

    </package>

</struts>

创建hello.jsp,内容如下:

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>

<%

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%>">

    <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 to Struts2

  </body>

</html>