defaultAction是什么意思呢?
默认的Action!
<default-action-ref name="index"></default-action-ref> 默认的action的引用;当别人访问这个action的时候,如果找不到对应的action
默认就用这个action了,
如果没有默认action的引用,那么我们在url中输入一个地址时候,action不能在struts.xml
文件中找到,那么这时就会报错,但是如果有了默认的action引用,就不会出现这种情况了
--------------------------------------Hongten-----------------------------------
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> <constant name="struts.devMode" value="true" /> <package name="default" namespace="/" extends="struts-default"> <default-action-ref name="index"></default-action-ref> <action name="index"> <result>/default.jsp</result> </action> </package> </struts>
--------------------------------------Hongten-----------------------------------
default.jsp
代码:
<?xml version="1.0" encoding="GB18030" ?> <%@ page language="java" contentType="text/html; charset=GB18030" pageEncoding="GB18030"%> <%@taglib uri="/struts-tags" prefix="s" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=GB18030" /> <title>DefaultAction</title> </head> <body> Default Action! </body> </html>