<bdo id='p1LL8'></bdo><ul id='p1LL8'></ul>

      <i id='p1LL8'><tr id='p1LL8'><dt id='p1LL8'><q id='p1LL8'><span id='p1LL8'><b id='p1LL8'><form id='p1LL8'><ins id='p1LL8'></ins><ul id='p1LL8'></ul><sub id='p1LL8'></sub></form><legend id='p1LL8'></legend><bdo id='p1LL8'><pre id='p1LL8'><center id='p1LL8'></center></pre></bdo></b><th id='p1LL8'></th></span></q></dt></tr></i><div id='p1LL8'><tfoot id='p1LL8'></tfoot><dl id='p1LL8'><fieldset id='p1LL8'></fieldset></dl></div>
      1. <legend id='p1LL8'><style id='p1LL8'><dir id='p1LL8'><q id='p1LL8'></q></dir></style></legend>

        <tfoot id='p1LL8'></tfoot>

        <small id='p1LL8'></small><noframes id='p1LL8'>

        使用 Struts 应用程序时出现错误 404 问题

        Error 404 issues using Struts application(使用 Struts 应用程序时出现错误 404 问题)
      2. <legend id='QOxkf'><style id='QOxkf'><dir id='QOxkf'><q id='QOxkf'></q></dir></style></legend>

        <tfoot id='QOxkf'></tfoot>

      3. <i id='QOxkf'><tr id='QOxkf'><dt id='QOxkf'><q id='QOxkf'><span id='QOxkf'><b id='QOxkf'><form id='QOxkf'><ins id='QOxkf'></ins><ul id='QOxkf'></ul><sub id='QOxkf'></sub></form><legend id='QOxkf'></legend><bdo id='QOxkf'><pre id='QOxkf'><center id='QOxkf'></center></pre></bdo></b><th id='QOxkf'></th></span></q></dt></tr></i><div id='QOxkf'><tfoot id='QOxkf'></tfoot><dl id='QOxkf'><fieldset id='QOxkf'></fieldset></dl></div>

        <small id='QOxkf'></small><noframes id='QOxkf'>

        • <bdo id='QOxkf'></bdo><ul id='QOxkf'></ul>

              <tbody id='QOxkf'></tbody>

                  本文介绍了使用 Struts 应用程序时出现错误 404 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  几天以来,我在运行 Struts Web 应用程序时遇到了一些问题.我尝试了 StackOverflow 中与我的问题相关的几种解决方案,但没有一个有效.

                  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.

                  web.xml:

                  <display-name>Struts2 Application</display-name>
                  <filter>
                      <filter-name>struts2</filter-name>
                      <filter-class>
                  
                          org.apache.struts2.dispatcher.FilterDispatcher
                      </filter-class>
                  </filter>
                  <filter-mapping>
                      <filter-name>struts2</filter-name>
                      <url-pattern>/*</url-pattern>
                  
                  </filter-mapping>
                  <welcome-file-list>
                      <welcome-file>Login.jsp</welcome-file>
                  </welcome-file-list>
                  

                  struts.xml:

                  <struts>
                      <constant name="struts.enable.DynamicMethodInvocation"
                          value="false" />
                      <constant name="struts.devMode" value="false" />
                  
                      <constant name="struts.custom.i18n.resources"
                          value="ApplicationResources" />
                  
                      <package name="default" extends="struts-default" namespace="/">
                  
                          <action name="login"
                              class="net.viralpatel.struts2.LoginAction">
                              <result name="success">Welcome.jsp</result>
                              <result name="error">Login.jsp</result>
                  
                          </action>
                      </package>
                  </struts>
                  

                  Login.jsp:

                  <%@ page contentType="text/html; charset=UTF-8"%>
                  <%@ taglib prefix="s" uri="/struts-tags"%>
                  <html>
                  <head>
                  
                  <title>Struts 2 - Login Application | ViralPatel.net</title>
                  </head>
                  
                  <body>
                  <h2>Struts 2 - Login Application</h2>
                  <s:actionerror />
                  <s:form action="login.action" method="post">
                  
                      <s:textfield name="username" key="label.username" size="20" />
                      <s:password name="password" key="label.password" size="20" />
                  
                      <s:submit method="execute" key="label.login" align="center" />
                  </s:form>
                  </body>
                  </html>
                  

                  LoginAction.java:

                  package net.viralpatel.struts2;
                  
                  public class LoginAction {
                      private String username;
                      private String password;
                  
                      public String execute() {
                  
                          if (this.username.equals("admin")
                                  && this.password.equals("admin123")) {
                              return "success";
                          } else {
                              return "error";
                          }
                      }
                  
                      public String getUsername() {
                          return username;
                      }
                  
                      public void setUsername(String username) {
                          this.username = username;
                      }
                  
                      public String getPassword() {
                          return password;
                      }
                  
                      public void setPassword(String password) {
                          this.password = password;
                      }
                  }
                  

                  我添加的库:

                  • commons-logging-1.1.3.jar
                  • freemarker-2.3.19.jar
                  • ognl-3.0.6.jar
                  • struts2-core-2.3.15.1.jar
                  • xwork-core-2.3.15.1.jar

                  访问 URL 时出错:

                  http://localhost:8080/StrutsHelloWorld/

                  HTTP Status 404 - /StrutsHelloWorld/
                  
                  type Status report
                  
                  message /StrutsHelloWorld/
                  
                  description The requested resource is not available.
                  
                  Apache Tomcat/7.0.42
                  

                  我试过这个教程.

                  我的控制台上没有错误,问题视图.

                  There are no errors on my console, problem view.

                  推荐答案

                  错误404表示你请求的资源不可用,同指没有映射到请求URL的动作.

                  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 已弃用,可能不适用于当前的 Struts 版本,请改用 StrutsPrepareAndExcecuteFilter.

                  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>
                  

                  struts.xml中添加如下

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

                  这会将您转到登录页面.还可以考虑使用 JSP 资源的绝对路径.

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

                  在JSP中使用需要重写的表单

                  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>
                  

                  action 属性中使用动作名称并提供 namespace,就像您在包配置中所做的那样.

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

                  s:submit标签中使用method="execute"是没用的,默认使用execute方法,它会无法工作,因为您已关闭 DMI在 Struts 配置中.

                  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.

                  WEB-INF/lib 中的旧库之上添加 库并没有太大帮助,您的应用程序可能无法运行,直到您删除并用高版本替换所有低版本库,并添加当前版本的 Struts 框架所需的新库.

                  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.

                  这篇关于使用 Struts 应用程序时出现错误 404 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                  How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                  Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                  Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                  How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                  How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)
                    • <bdo id='o2IWs'></bdo><ul id='o2IWs'></ul>

                        <i id='o2IWs'><tr id='o2IWs'><dt id='o2IWs'><q id='o2IWs'><span id='o2IWs'><b id='o2IWs'><form id='o2IWs'><ins id='o2IWs'></ins><ul id='o2IWs'></ul><sub id='o2IWs'></sub></form><legend id='o2IWs'></legend><bdo id='o2IWs'><pre id='o2IWs'><center id='o2IWs'></center></pre></bdo></b><th id='o2IWs'></th></span></q></dt></tr></i><div id='o2IWs'><tfoot id='o2IWs'></tfoot><dl id='o2IWs'><fieldset id='o2IWs'></fieldset></dl></div>

                        <tfoot id='o2IWs'></tfoot>

                          1. <small id='o2IWs'></small><noframes id='o2IWs'>

                          2. <legend id='o2IWs'><style id='o2IWs'><dir id='o2IWs'><q id='o2IWs'></q></dir></style></legend>
                              <tbody id='o2IWs'></tbody>