gpt4 book ai didi

java - 动态 Web 应用程序在 Eclipse 中运行,但不在 Tomcat 中运行

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

我一直在开发一个小型应用程序,主要是作为学习练习。

我一直在分阶段引入新事物。我已经准备好添加 Struts 2。

现在,我正在尝试添加 Tiles,但仍然遇到问题。如果我右键单击该项目并“run As” -> “Run on Server”它将按预期运行。

如果我将应用程序作为 WAR 文件部署到本地 Tomcat 实例,它将部署正常,但当我尝试访问该应用程序时,它会失败,并在图 block 定义文件中显示 IllegalArgumentException

我在 WEB-INF/lib 目录中有 Maven 资源。但是当我导出war文件时,我仍然遗漏了一些东西。我已经查看了所有日志文件,但看不出有什么不同。 Eclipse 中配置的服务器指向我单独运行的同一台服务器。这是Tomcat v7.0.70。

这是我尝试访问网页时的输出:

Struts Problem Report

Struts has detected an unhandled exception:
Messages:

Illegal character in path at index 13: file:///C:/My Programs/apache-tomcat-7.0.70/webapps/TeamInfo/WEB-INF/classes/tiles-def.xml
Illegal character in path at index 13: file:///C:/My Programs/apache-tomcat-7.0.70/webapps/TeamInfo/WEB-INF/classes/tiles-def.xml

堆栈跟踪

java.lang.IllegalArgumentException: Illegal character in path at index 13: file:///C:/My Programs/apache-tomcat-7.0.70/webapps/TeamInfo/WEB-INF/classes/tiles-def.xml

java.net.URI.create(Unknown Source)
org.apache.struts2.tiles.StrutsWildcardServletApplicationContext.getResource(StrutsWildcardServletApplicationContext.java:105)
org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO.loadRawDefinitionsFromResources(CachingLocaleUrlDefinitionDAO.java:232)
org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO.loadRawDefinitionsFromResources(CachingLocaleUrlDefinitionDAO.java:225)
org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO.loadRawDefinitionsFromResources(CachingLocaleUrlDefinitionDAO.java:225)
org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO.loadDefinitionsFromResources(CachingLocaleUrlDefinitionDAO.java:203)
org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO.loadDefinitions(CachingLocaleUrlDefinitionDAO.java:192)
org.apache.tiles.definition.dao.ResolvingLocaleUrlDefinitionDAO.loadDefinitions(ResolvingLocaleUrlDefinitionDAO.java:68)
org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO.checkAndloadDefinitions(CachingLocaleUrlDefinitionDAO.java:174)
org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO.getDefinitions(CachingLocaleUrlDefinitionDAO.java:131)
org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO.getDefinition(CachingLocaleUrlDefinitionDAO.java:105)
org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO.getDefinition(CachingLocaleUrlDefinitionDAO.java:49)
org.apache.tiles.definition.UnresolvingLocaleDefinitionsFactory.getDefinition(UnresolvingLocaleDefinitionsFactory.java:89)
org.apache.tiles.impl.BasicTilesContainer.getDefinition(BasicTilesContainer.java:286)
org.apache.tiles.impl.BasicTilesContainer.isValidDefinition(BasicTilesContainer.java:273)
org.apache.tiles.TilesContainerWrapper.isValidDefinition(TilesContainerWrapper.java:88)
org.apache.tiles.impl.mgmt.CachingTilesContainer.isValidDefinition(CachingTilesContainer.java:100)
org.apache.struts2.views.tiles.TilesResult.doExecute(TilesResult.java:139)
org.apache.struts2.result.StrutsResultSupport.execute(StrutsResultSupport.java:208)
com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:366)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:270)
com.opensymphony.xwork2.interceptor.LoggingInterceptor.intercept(LoggingInterceptor.java:68)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:240)
com.opensymphony.xwork2.interceptor.TimerInterceptor.intercept(TimerInterceptor.java:121)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:240)
org.apache.struts2.factory.StrutsActionProxy.execute(StrutsActionProxy.java:54)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:556)
org.apache.struts2.dispatcher.ExecuteOperations.executeAction(ExecuteOperations.java:81)
org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:113)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218)
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:442)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1082)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:623)
org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2517)
org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2506)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Unknown Source)


java.net.URISyntaxException: Illegal character in path at index 13: file:///C:/My Programs/apache-tomcat-7.0.70/webapps/TeamInfo/WEB-INF/classes/tiles-def.xml

java.net.URI$Parser.fail(Unknown Source)
java.net.URI$Parser.checkChars(Unknown Source)
java.net.URI$Parser.parseHierarchical(Unknown Source)
java.net.URI$Parser.parse(Unknown Source)
java.net.URI.<init>(Unknown Source)
java.net.URI.create(Unknown Source)
org.apache.struts2.tiles.StrutsWildcardServletApplicationContext.getResource(StrutsWildcardServletApplicationContext.java:105)
org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO.loadRawDefinitionsFromResources(CachingLocaleUrlDefinitionDAO.java:232)
org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO.loadRawDefinitionsFromResources(CachingLocaleUrlDefinitionDAO.java:225)
org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO.loadRawDefinitionsFromResources(CachingLocaleUrlDefinitionDAO.java:225)
org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO.loadDefinitionsFromResources(CachingLocaleUrlDefinitionDAO.java:203)
org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO.loadDefinitions(CachingLocaleUrlDefinitionDAO.java:192)
org.apache.tiles.definition.dao.ResolvingLocaleUrlDefinitionDAO.loadDefinitions(ResolvingLocaleUrlDefinitionDAO.java:68)
org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO.checkAndloadDefinitions(CachingLocaleUrlDefinitionDAO.java:174)
org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO.getDefinitions(CachingLocaleUrlDefinitionDAO.java:131)
org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO.getDefinition(CachingLocaleUrlDefinitionDAO.java:105)
org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO.getDefinition(CachingLocaleUrlDefinitionDAO.java:49)
org.apache.tiles.definition.UnresolvingLocaleDefinitionsFactory.getDefinition(UnresolvingLocaleDefinitionsFactory.java:89)
org.apache.tiles.impl.BasicTilesContainer.getDefinition(BasicTilesContainer.java:286)
org.apache.tiles.impl.BasicTilesContainer.isValidDefinition(BasicTilesContainer.java:273)
org.apache.tiles.TilesContainerWrapper.isValidDefinition(TilesContainerWrapper.java:88)
org.apache.tiles.impl.mgmt.CachingTilesContainer.isValidDefinition(CachingTilesContainer.java:100)
org.apache.struts2.views.tiles.TilesResult.doExecute(TilesResult.java:139)
org.apache.struts2.result.StrutsResultSupport.execute(StrutsResultSupport.java:208)
com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:366)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:270)
com.opensymphony.xwork2.interceptor.LoggingInterceptor.intercept(LoggingInterceptor.java:68)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:240)
com.opensymphony.xwork2.interceptor.TimerInterceptor.intercept(TimerInterceptor.java:121)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:240)
org.apache.struts2.factory.StrutsActionProxy.execute(StrutsActionProxy.java:54)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:556)
org.apache.struts2.dispatcher.ExecuteOperations.executeAction(ExecuteOperations.java:81)
org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:113)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218)
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:442)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1082)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:623)
org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2517)
org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2506)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
j ava.lang.Thread.run(Unknown Source)


You are seeing this page because development mode is enabled. Development mode, or devMode, enables extra debugging behaviors and reports to assist developers. To disable this mode, set:
struts.devMode=false

in your WEB-INF/classes/struts.properties file.

这是web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

<display-name>Team Info</display-name>

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/config/SpringBeans.xml</param-value>
</context-param>
<context-param>
<param-name>isLog4jAutoInitializationDisabled</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>tilesDefinitions</param-name>
<param-value>/WEB-INF/classes/tiles-def.xml</param-value>
</context-param>

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
</listener>

<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>

<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

</web-app>

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.devMode" value="true" />

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

<result-types>
<result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult" />
</result-types>

<interceptors>
<interceptor name="authentication" class="com.teaminfo.interceptors.AuthenticationInterceptor" />
<interceptor-stack name="authStack">
<interceptor-ref name="timer" />
<interceptor-ref name="logger" />
<interceptor-ref name="authentication" />
<interceptor-ref name="defaultStack" />
</interceptor-stack>
</interceptors>

<default-interceptor-ref name="authStack" />

<default-action-ref name="dashboard" />

<global-results>
<result name="need_login" type="tiles">login</result>
<result name="exception">/jsp/error.jsp</result>
</global-results>

<global-exception-mappings>
<exception-mapping exception="java.lang.Exception" result="exception" />
</global-exception-mappings>

<action name="login" class="com.teaminfo.action.LoginAction">
<interceptor-ref name="defaultStack" />
<result name="success" type="redirectAction">dashboard</result>
<result name="input" type="tiles">login</result>
</action>
<action name="dashboard" class="com.teaminfo.action.Dashboard">
<result name="manager" type="tiles">manager</result>
<result name="associate" type="tiles">associate</result>
</action>
</package>

</struts>

图 block 配置

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
"http://tiles.apache.org/dtds/tiles-config_2_0.dtd">

<tiles-definitions>
<definition name="mainTemplate" template="/jsp/layout.jsp">
<put-attribute name="title" value="Team Info" />
<put-attribute name="header" value="/jsp/header.jsp" />
<put-attribute name="menu" value="/jsp/menu.jsp" />
<put-attribute name="body" value="/jsp/body.jsp" />
<put-attribute name="footer" value="/jsp/footer.jsp" />
</definition>

<definition name="login" extends="mainTemplate">
<put-attribute name="title" value="Team Info Login" />
<put-attribute name="menu" value="/jsp/menu.jsp" />
<put-attribute name="body" value="/jsp/login.jsp" />
</definition>

<definition name="admin" extends="mainTemplate">
<put-attribute name="title" value="Team Info Admin" />
<put-attribute name="menu" value="/jsp/admin/menu.jsp" />
<put-attribute name="body" value="/jsp/admin/body.jsp" />
</definition>

<definition name="manager" extends="mainTemplate">
<put-attribute name="title" value="Team Info Manager" />
<put-attribute name="menu" value="/jsp/manager/menu.jsp" />
<put-attribute name="body" value="/jsp/manager/body.jsp" />
</definition>

<definition name="associate" extends="mainTemplate">
<put-attribute name="title" value="Team Info Manager" />
<put-attribute name="menu" value="/jsp/associate/menu.jsp" />
<put-attribute name="body" value="/jsp/associate/body.jsp" />
</definition>

</tiles-definitions>

最佳答案

它不喜欢路径中的空格。因此,在这种情况下,应使用 %20 更改空间。使用replaceAll("","%20");

否则,您可以使用 URLEncoder 进行编码。

String pathOfFile = "file:///C:/My Programs/apache-tomcat-7.0.70/webapps/TeamInfo/WEB-INF/classes/tiles-def.xml";
pathOfFile = URLEncoder.encode(pathOfFile, "UTF-8");

更新1:

对于图 block ,您可以按如下方式替换参数值

    <param-value>
/WEB-INF/tiles-defs.xml,/org/apache/tiles/classpath-defs.xml
</param-value>

而不是

<param-value>/WEB-INF/classes/tiles-def.xml</param-value>

更多信息,您可以通过this tutorial .

关于java - 动态 Web 应用程序在 Eclipse 中运行,但不在 Tomcat 中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38702950/

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