gpt4 book ai didi

java - 如何在 Struts 2 中声明 "unknown handlers"?

转载 作者:行者123 更新时间:2023-12-02 09:15:12 25 4
gpt4 key购买 nike

我一直致力于如何使用 Spring 和 Struts2 解决 Java Enterprise 中的错误 404 和 NoSuchMethodException 昨天,我读到未知处理程序可以帮助我解决这些问题。

我已将其放入我的 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.3.dtd">
<struts>
<bean name="unknownhandler" type="com.opensymphony.xwork2.UnknownHandler" class="UnknownActionHandler"/>

<unknown-handler-stack>
<unknown-handler-ref name="unknownhandler"/>
<!--<unknown-handler-ref name="error" />-->
</unknown-handler-stack>

<constant name="struts.ui.theme" value="simple"/>
<constant name="struts.objectFactory.spring.autoWire" value="name"/>
<constant name="struts.locale" value="es_MX" />
<constant name="struts.i18n.encoding" value="UTF-8" />
<constant name="struts.custom.i18n.resources" value="org.aporta.model.resources.etiquetas, org.aporta.bss.resources.CodesBss"/>
<constant name="struts.devMode" value="true" />
<constant name="struts.configuration.xml.reload" value="true"/>
<constant name="struts.enable.DynamicMethodInvocation" value="true" />

...more code

</struts>

当我运行该项目时,出现此错误:

org.xml.sax.SAXParseException; systemId: file:/home/paulfelix/Documents/workingit/portal/src/java/portal.xml; lineNumber: 33; columnNumber: 26; Element type "unknown-handler-stack" must be declared.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:134)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:437)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:368)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:325)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleStartElement(XMLDTDValidator.java:1906)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.startElement(XMLDTDValidator.java:742)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:378)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2770)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:117)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:649)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:333)
at com.opensymphony.xwork2.util.DomHelper.parse(DomHelper.java:117)

...more code below.

在哪里可以声明未知的处理程序堆栈?

谁能给我一个清晰的例子来说明如何实现unknownhandlers?

最佳答案

DTD 通常是您的 friend ;知道如何阅读它可以节省大量时间:

<!ELEMENT struts ((package|include|bean|constant)*, unknown-handler-stack?)>

即,在配置文件的末尾。

请注意,它们仅从 ~2.1 开始可用。

关于java - 如何在 Struts 2 中声明 "unknown handlers"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24655662/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com