网上很多文章说的都不对,或者设置起来很麻烦。
其实这个共存很简单,不需要另外的设置。
首先就是web.xml修改,加入servlet声明,并且修改struts2相关配置
//servlet
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>medalpay</servlet-name>
<servlet-class>com.lx.ad.contrl.MedalPayAction</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>medalpay</servlet-name>
<url-pattern>/medalpay.servlet</url-pattern>
</servlet-mapping>
//struts2 把/* 改为*.do
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
//servlet代码部分如下调用spring bean
WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
bService = (MedalGainService)wac.getBean("medalGainService");
bService.updateUserMedalCount(userId, medalId, addcount);