1 Action配置的各项默认值 2 result配置的各种视图转发类型 3

1>如果没有为action指定class,默认是ActionSupport

2>如果没有为action指定method,默认执行action中的execute() 方法。

3>如果没有指定resultname属性,默认值为success

<?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>
		<action name="addUI">
			<result>/WEB-INF/page/employeeAdd.jsp</result> //只有浏览器内部转发的时候才可能转发到web-info 下面,重定向是不能转发到这里的
		</action>
	</package>
</struts>

employeeAdd.jsp 

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>My JSP 'employeeAdd.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">
  </head>
  
  <body>
    <form action="/xxx">
    	姓名:<input type="text" name="xxx">
    </form>
  </body>
</html>
package cn.itcast.action;

public class HelloWorldAction {
	private String msg;
	
	public String getMessage() {
		return msg;
	}


	public String execute(){
		this.msg = "我的第一个struts2应用";
		return "success";
	}
}

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" 
	xmlns="http://java.sun.com/xml/ns/j2ee" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
	http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
	
    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

1>如果没有为action指定class,默认是ActionSupport

2>如果没有为action指定method,默认执行action中的execute() 方法。

3>如果没有指定resultname属性,默认值为success

猜你喜欢

转载自blog.csdn.net/qq_20610631/article/details/81361047