gpt4 book ai didi

java - JSP/JasperException : File [/xyz. jsp] 找不到

转载 作者:行者123 更新时间:2023-11-28 22:24:38 27 4
gpt4 key购买 nike

我已经搜索过但找不到我的场景,这很烦人。

当我在 Eclipse 中运行我的项目时,它工作正常,但是当我(通过 WAR)部署到我的生产服务器时,我得到 JasperException File Not Found。这只会发生在不在根文件夹中的 JSP 上。我很难过。本质上,我正在为我的安全过滤器使用/secure/上下文。

文件结构: FileStructure in Eclipse

Web.XML:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
id="WebApp_ID" version="4.0">

<display-name>Name Here</display-name>
<description>Description Here</description>

<filter>
<filter-name>AuthenticationFilter</filter-name>
<filter-class>com.example.package.AuthFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>AuthenticationFilter</filter-name>
<url-pattern>/secure/*</url-pattern>
</filter-mapping>

<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

JSP(是的,这是现在的整个 JSP,因为我才刚刚开始):*注意:JSTL成员是在header中加载的

<%@include file="/inc.header.jsp"%> <!-- file-not-found -->
<div class="m-2">

<h3>SECURE INDEX</h3>

<h5>User Details</h5>
<table class="table table-sm table-hover table-responsive table-bordered">
<tbody>
<c:forEach var="detail" items="${user.userdetails}">
<tr>
<td><c:out value="${detail.key}"/></td>
<td><c:out value="${detail.value}"/></td>
</tr>
</c:forEach>
</tbody>
</table>

</div>
<%@include file="/inc.footer.jsp"%> <!-- file-not-found -->

错误信息:

Exception

org.apache.jasper.JasperException: /index.jsp (line: [1], column: [2]) File [/inc.header.jsp] not found
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:42)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:292)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:98)
org.apache.jasper.compiler.Parser.processIncludeDirective(Parser.java:345)
org.apache.jasper.compiler.Parser.parseIncludeDirective(Parser.java:380)
org.apache.jasper.compiler.Parser.parseDirective(Parser.java:481)
org.apache.jasper.compiler.Parser.parseFileDirectives(Parser.java:1797)
org.apache.jasper.compiler.Parser.parse(Parser.java:141)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:244)
org.apache.jasper.compiler.ParserController.parseDirectives(ParserController.java:127)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:202)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:385)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:362)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:346)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:603)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:383)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330)
javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)

非常感谢任何想法。

编辑 --- 我发现如果我在“不安全”文件夹中做同样的事情,它会工作一秒钟。所以有些事情我无法全神贯注……AuthFilter 非常简单,我看不出有什么问题。

AuthFilter.java:

package com.example.package;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
//import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

// @WebFilter("/AuthFilter") /* removed in favor of web.xml */
public class AuthFilter implements Filter {

//private ServletContext context;

public void init(FilterConfig fConfig) throws ServletException {
//this.context = fConfig.getServletContext();
//this.context.log("AuthenticationFilter initialized");
}

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse res = (HttpServletResponse) response;

//String uri = req.getRequestURI();
//this.context.log("Requested Resource::"+uri);
//System.out.println("Requested Resource::"+uri);

HttpSession session = req.getSession(true);

Boolean isLoggedIn = false;
if (session != null) isLoggedIn = (Boolean)session.getAttribute("isLoggedIn");
if (isLoggedIn == null) isLoggedIn = false;

if( !isLoggedIn ){
//this.context.log("Unauthorized access request");
res.sendRedirect("/login.jsp");
}else{
// pass the request along the filter chain
chain.doFilter(request, response);
}
}

public void destroy() {
//TODO close any resources here
}
}

编辑:我可能正在做某事。提示:这是一个“虚拟上下文”或任何你称之为的东西。我的http://localhost/在哪里实际上不起作用。必须是 http://app.example.com/被Tomcat识别。我在想 tomcat 不恰本地将我的“安全”文件夹解析为独立的网络应用程序。我在这个系统上有多个虚拟主机,没有碰巧使用这个概念,也没有子文件夹索引文件。当我将页眉/页脚文件移动到/secure/时出现新错误,我现在收到“绝对 uri: [ http://java.sun.com/jsp/jstl/core] 无法在 web.xml 或随此应用程序部署的 jar 文件中解析” .... 因此,我认为 Tomcat 认为我的/secure/是一个独立的应用程序。

Server.xml 条目:

<Host name="app.example.com" appBase="webapp_hosts/app.example.com" unpackWARs="false" autoDeploy="true" reloadable="true">
<Alias>app.example.server</Alias>
<Alias>app.example.local</Alias>
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="crm_access_log" suffix=".txt"
pattern="%h %l %u %t &quot;%r&quot; %s %b" />
<Context path="/" docBase="" debug="0" reloadable="true"/>
</Host>

最佳答案

您是说,如果将 jsp 移动到安全文件夹中,所有请求都会失败。此请求将由您的过滤器过滤,如果不查看过滤器的实现,很难找到答案。

如果可以,请分享过滤器和监听器。

关于java - JSP/JasperException : File [/xyz. jsp] 找不到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52941784/

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