我一直在努力解决如何使用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.
我在哪里可以声明未知的处理程序堆栈?
有人能给我一个明确的例子来说明如何实现未知的处理程序吗?
答案 0 :(得分:0)
DTD通常是你的朋友;知道如何阅读它可以节省大量时间:
<!ELEMENT struts ((package|include|bean|constant)*, unknown-handler-stack?)>
即,在配置文件的末尾。
请注意,它们仅在~2.1之后可用。