Error 404 issues using Struts application

前端 未结 1 754
-上瘾入骨i
-上瘾入骨i 2020-12-19 17:14

I am having some issues running a Struts web app since few days. I tried several solutions from StackOverflow relating to my problem but none of them works.

相关标签:
1条回答
  • 2020-12-19 17:35

    The error 404 means that resource you have requested is not available, the same referred to the action that is didn't map to the request URL.

    FilterDispatcher is deprecated and may not work with the current Struts version, use StrutsPrepareAndExcecuteFilter instead.

    <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>
    

    in the struts.xml add the following

    <package name="default" extends="struts-default" namespace="/">
       <action name=""><result>/Login.jsp</result></acton> 
    

    this will forward you to the login page. Also consider to use absolute paths to the JSP resources.

    In the JSP use the form that needs to rewrite to

    <s:form namespace="/" action="login" method="post">
    
        <s:textfield name="username" key="label.username" size="20" />
        <s:password name="password" key="label.password" size="20" />
    
        <s:submit key="label.login" align="center" />
    </s:form>
    

    In the action attribute use the action name and provide namespace as you did in the package configuration.

    Using method="execute" is useless in the s:submit tag, the method execute used by default, and it will not work because you have turned off DMI in the Struts configuration.

    Adding libraries over the old libraries in the WEB-INF/lib doesn't help so much and your application probably would not work, until you remove and replace all lower version libraries with higher version and add new libraries needed by the current version of Struts framework.

    0 讨论(0)
提交回复
热议问题