Error 404 issues using Struts application

主宰稳场 提交于 2019-11-29 11:14:28

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!