gpt4 book ai didi

java - 为什么我无法获取jsp的思想路径?

转载 作者:行者123 更新时间:2023-11-30 06:48:36 28 4
gpt4 key购买 nike

我在我的 Java EE 项目中使用 struts:

在我的 loading.jsp 中,如果我使用下面的 src,我将收到 404 错误:

<IFRAME src="${pageContext.request.contextPath}/WEB-INF/page/menu/alermDevice.jsp" name="dev" id="dev" frameBorder="0" width="500" scrolling="auto" height="400">
</IFRAME>

但是如果我使用下面的src:

<IFRAME src="elecMenuAction_alermDevice.do" name="dev" id="dev" frameBorder="0" width="500" scrolling="auto" height="400">
</IFRAME>

我会得到正确的信息。

这是我的struts.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>

<constant name="struts.devMode" value="true"></constant>
<constant name="struts.ui.theme" value="simple"></constant>
<constant name="struts.action.extension" value="do"></constant>

<package name="system" namespace="/system" extends="struts-default">
<action name="elecTextAction_*" class="elecTextAction" method="{1}">
<result name="save">/system/textAdd.jsp</result>
</action>
<action name="elecMenuAction_*" class="elecMenuAction" method="{1}">
<result name="menuHome">/WEB-INF/page/menu/home.jsp</result>
<result name="title">/WEB-INF/page/menu/title.jsp</result>
<result name="left">/WEB-INF/page/menu/left.jsp</result>
<result name="change">/WEB-INF/page/menu/change.jsp</result>
<result name="loading">/WEB-INF/page/menu/loading.jsp</result>
<result name="logout" type="redirect">index.jsp</result>
<result name="alermStation">/WEB-INF/page/menu/alermStation.jsp</result>
<result name="alermDevice">/WEB-INF/page/menu/alermDevice.jsp</result>
</action>
</package>
</struts>

为什么我使用的路径无法访问JSP?只用我的 Action 就可以得到了吗?

最佳答案

Web 服务器无法从 WEB-INF 文件夹及以下文件夹获取资源。当调用操作时,它会返回一个响应作为结果的执行。它使用结果类型dispatcher,默认情况下使用该类型将请求转发到指定的 URL(请求的 JSP 页面)。

Dispatcher Result

Includes or forwards to a view (usually a jsp). Behind the scenes Struts will use a RequestDispatcher, where the target servlet/JSP receives the same request/response objects as the original servlet/JSP. Therefore, you can pass data between them using request.setAttribute() - the Struts action is available.

There are three possible ways the result can be executed:

  • If we are in the scope of a JSP (a PageContext is available), PageContext's PageContext#include(String) method is called.

  • If there is no PageContext and we're not in any sort of include (there is no "javax.servlet.include.servlet_path" in the request attributes), then a call to RequestDispatcher#forward(javax.servlet.ServletRequest,
    javax.servlet.ServletResponse)
    is made.

  • Otherwise, RequestDispatcher#include(javax.servlet.ServletRequest,
    javax.servlet.ServletResponse)
    is called.

<小时/>

当调用 servlet 调度程序时,它没有这样的限制,并且可以返回具有与最初请求相同的响应的资源。

关于java - 为什么我无法获取jsp的思想路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43255549/

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