在我的Struts2应用程序中,我试图包含一个可以处理Ajax请求的Servlet。我在excludePattern
中包含了struts.xml
,并在web.xml
中映射了servlet。我仍然无法点击Servlet。这是我的XML文件。
Struts.xml
<struts>
<constant name="struts.devMode" value="true" />
<constant name="struts.action.excludePattern" value="/ajaxservlet"/>
<package name="helloworld" extends="struts-default">
<action name="loginAction" class="controller.loginAction" method="execute">
<result name="success">home.jsp</result>
<result name="error">index.jsp</result>
</action>
</package>
</struts>
这是我的web.xml
:
<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>
<servlet>
<servlet-name>control</servlet-name>
<servlet-class>controller.control</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>control</servlet-name>
<url-pattern>/ajaxservlet</url-pattern>
</servlet-mapping>
答案 0 :(得分:0)
尝试更改servlet的映射
<servlet>
<servlet-name>control</servlet-name>
<servlet-class>controller.control</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>control</servlet-name>
<url-pattern>/ajaxservlet/*</url-pattern>
</servlet-mapping>
并相应地修改struts配置
<constant name="struts.action.excludePattern" value="/ajaxservlet/?.*"/>