Struts 2动作类不起作用 [英] Struts 2 action class not working

查看:240
本文介绍了Struts 2动作类不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在使用struts2来开发一个Web应用程序。

我已经为struts2包含了所需的jar,但是当它要调用struts动作类时它是抛出404错误。

控制台没有错误,浏览器没有显示struts.xml调用动作类时显示的.action扩展名。

我正在使用 jdk 1.6 struts 2.0

我错过任何负责这一切的jar 。


I am using struts2 for developing a web application.
I have include the required jars for struts2 but when it is going to call the struts action class it is throwing 404 error.
There is no error on console and browser does not showing .action extension whitch it shows when struts.xml call an action class.
I am using jdk 1.6 and struts 2.0.
Am I missing any jar who is responsible for all this.

在jsp中我只是从

调用该函数< s:form action = Mergexmlactionmethod =post/>

这是我的struts.xml和web.xml

Here is my struts.xml and web.xml

struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!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.multipart.maxSize" value="6000000000" /> 

  <package name="default" namespace="/jsp" extends="struts-default">
    <action name="Mergexmlaction" class="com.hm.merge.mergeaction.Mergexmlaction">
      <result name="success" >/jsp/Result.jsp</result>
      <result name="error" >/jsp/Browse_multiplexmlfiles.jsp</result> 
      <interceptor-ref name="fileUpload">
        <param name="maximumSize">600000000</param> 
      </interceptor-ref> 
    </action>
  </package>
</struts>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="xml_file_merging" version="2.4"
    xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> 
  <display-name>xml_file_merging</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>jsp/Browse_multiplexmlfiles.jsp</welcome-file>
    </welcome-file-list>
</web-app>


推荐答案

存在一些问题。

<package name="default" namespace="/jsp" extends="struts-default">

1)我建议反对拥有jsp的命名空间,它没有任何意义。命名空间应该对应用程序和/或用户有意义。

1) I'd recommend against having a namespace of "jsp", it doesn't make any sense. Namespaces should be something meaningful to the application and/or user.

  <action name="Mergexmlaction" class="com.hm.merge.mergeaction.Mergexmlaction">

2)请勿使用操作命名操作,将是 .action 扩展名,或根本没有扩展名。无论哪种方式,没有理由在第一种情况下复制动作,如果没有扩展,没有理由使用动作。只需mergexml,mergeXml等等。

2) Don't name an action with "action", there will either be a .action extension, or no extension at all. Either way, there's no reason to duplicate "action" in the first case, and no reason to use "action" if there's no extension. Just "mergexml", "mergeXml", etc.

    <result name="success" >/jsp/Result.jsp</result>

3)我建议将您的JSP页面放在 WEB-INF 以避免直接客户端访问。

3) I recommend putting your JSP pages under WEB-INF to avoid direct client access.

    <interceptor-ref name="fileUpload">

4)一旦声明任何拦截器,您必须声明所有拦截器。此操作只有一个拦截器在运行。这是可能的这没关系,但它几乎不是正确的事情。

4) Once you declare any interceptors, you must declare all interceptors. This action has only a single interceptor running. It's possible this is okay, but it's almost never the right thing to do.

<welcome-file>jsp/Browse_multiplexmlfiles.jsp</welcome-file>

5)这是最终的问题,取决于你的方式重新访问该应用程序。您将欢迎文件显示为JSP页面,可能使用S2标记。这不起作用:标签依赖于它们是完整的S2请求,价值堆栈等。

5) And this is the ultimate issue, depending on how you're accessing the application. You show the welcome file as being a JSP page, which is presumably using S2 tags. This won't work: the tags depend on their being a complete S2 request, a value stack, etc.

所有对S2应用程序的访问都应该通过S2进行动作,不是 JSP。如果您查看直接访问的JSP的呈现HTML,您将看不到呈现的名称空间和操作扩展名。

All access to an S2 app should take place through an S2 action, not a JSP. If you look at the rendered HTML for the directly-accessed JSP you'll see neither namespace nor action extension rendered.

这篇关于Struts 2动作类不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆