上使用servlet与支柱错误404 2(Error 404 on using servlets w

2019-10-19 05:53发布

我把所有的Struts的jar包括在WEB-INF/lib ,并导入到项目。 我试图从迁移基于简单的servlet项目Struts2的。 我添加过滤器标签在web.xml ,并在不断的标签struts.xml按照教程,但我得到404上的servlet调用。

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>Solution</display-name>
  <welcome-file-list>
    <welcome-file>Login.jsp</welcome-file>
  </welcome-file-list>

  <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>
    <display-name>LoginController</display-name>
    <servlet-name>LoginController</servlet-name>
    <servlet-class>com.tcs.controller.LoginController</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>LoginController</servlet-name>
    <url-pattern>/LoginController</url-pattern>
  </servlet-mapping>
</web-app>

struts.xml

<!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.action.excludePattern" value="/LoginController"></constant>
    <package name="default" extends="hibernate-default">    
    </package>
</struts>

错误JSP页面:

HTTP Status 404 - There is no Action mapped for namespace / and action name LoginController.
The requested resource (There is no Action mapped for namespace / and action name LoginController.) is not available.

Answer 1:

应该有一个模式

<constant name="struts.action.excludePattern" value="/LoginController/?.*"/>

和servlet映射应

<servlet>
  <servlet-name>LoginController</servlet-name>
  <servlet-class>com.tcs.controller.LoginController</servlet-class>
</servlet>
<servlet-mapping>
  <servlet-name>LoginController</servlet-name>
  <url-pattern>/LoginController/*</url-pattern>
</servlet-mapping>


文章来源: Error 404 on using servlets with struts 2