struts2 url 配置問題

struts2 默認只處理/* 和*.action。 因此在web.xml中,若是不加以說明。<url-pattern>標籤只能填寫*.action或/* 。若是想使用*.do, 則須要 在struts.xml中添加html

<constant name="struts.action.extension" value="do"/>  或者action和do同時使用web

<constant name="struts.action.extension" value="do,action"/>  apache

struts.xml:app

<struts>
	<constant name="struts.enable.DynamicMethodInvocation" value="true"/>
    <package name="default" extends="struts-default">
        <action name="login" class="example.structtest" >
            <result name="success">success.html</result>
            <result name="error">error.jsp</result>
        </action>
    </package>
</struts>

web.xml:jsp

<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>*.action</url-pattern>
  </filter-mapping>

index.xml:url

<form action="login.action">
	<input type="text" name="name"><br/>
    <input type="text" name="age"><br/>
    <input type="submit" name="submit" value="登陸"><br/>
</form>
相關文章
相關標籤/搜索