Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 无法解析JSPEException和PageContext_Spring_Jsp - Fatal编程技术网

Spring 无法解析JSPEException和PageContext

Spring 无法解析JSPEException和PageContext,spring,jsp,Spring,Jsp,这是一个关于 多亏了@kmb385,我才能够解决这个问题,但现在我的JSP文件中出现了以下eclipse错误 无法将javax.servlet.jsp.JspException解析为类型 及 无法将javax.servlet.jsp.PageContext解析为类型 根据kmb385的建议,这是我的控制器: @Controller public class AdminController { @RequestMapping("/") protected Mode

这是一个关于 多亏了@kmb385,我才能够解决这个问题,但现在我的JSP文件中出现了以下eclipse错误 无法将javax.servlet.jsp.JspException解析为类型 及

无法将javax.servlet.jsp.PageContext解析为类型

根据kmb385的建议,这是我的控制器:

@Controller
public class AdminController {

        @RequestMapping("/")
        protected ModelAndView handleRequestInternal(HttpServletRequest request,
            HttpServletResponse response) throws Exception {

            ModelAndView model = new ModelAndView("index");
            model.addObject("msg", "hello world");

            return model;
        }   
    }
这是我的index.jsp页面,以防万一:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<!-- <link type="text/css" rel="stylesheet" href="css/style.css"/> -->
<style type="text/css">
    <%@include file="css/style.css" %>
    </style>
<title>My Project - MainPage</title>
</head>
<body>
<h2 class="main_heading2">My Project - MainPage</h2>
<div style="float: right; width: 30%; text-align: center">
<p style="float:left;">an image should be here</p>
<img src="images/logo.jpg" alt="Logo"/>
<img src="${pageContext.servletContext.contextPath}/resources/images/logo.jpg" />
</div>

</body>

我的项目-主页
我的项目-主页
图像应该在这里

我在JSP验证器中禁用了它,因此遇到了“解决方案”,但请不要建议这样做,除非您能给出合理的理由。我宁愿正确地纠正这个问题

谢谢你的帮助

更新: 按照@kmb385的要求构建路径屏幕抓取

尝试将pom.xml中的
servlet api
依赖项设置为提供。此jar可能与tomcat提供的servlet-api.jar冲突

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
        <scope>provided</scope>
    </dependency>

javax.servlet
servlet api
2.5
假如
还要确保包含jsp api依赖项,再次按照提供的设置:

    <!-- Servlet -->
    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>javax.servlet.jsp-api</artifactId>
        <version>2.3.3</version>
        <scope>provided</scope>
    </dependency>

javax.servlet.jsp
javax.servlet.jsp-api
2.3.3
假如
右键单击项目>属性,确保所有maven依赖项都用于构建项目。在deployment assembly选项卡上,单击add按钮,然后单击Java构建路径条目,然后单击Maven依赖项,最后单击Finish

您可能还需要将maven依赖项添加到构建路径中。右键单击项目>Maven>更新项目配置。

尝试导入类

修改jsp的第一行,使其如下所示


添加到pom.xml依赖项中

     <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>jsp-api</artifactId>
        <version>2.1</version>
        <scope>provided</scope>
    </dependency>

javax.servlet

如果您已在maven中下载了所有依赖项,并且错误仍然存在,请按照以下步骤操作:

  • 右键单击项目并转到属性
  • 单击目标运行时间
  • 选中您正在使用的服务器前面的复选框
    这应该是可行的。

    如何解决javax.servlet.jsp.PageContext无法解析为类型

    1:-选择您的项目并右键单击

    2:-前往酒店

    3:-单击目标运行时

    4:-勾选“Apache Tomcat v8.0”

    我正在使用Apache v8.0,这将解决问题
    This will solve the problem 
    
    <!-- Need this to compile JSP -->
            <dependency>
                <groupId>org.apache.tomcat.embed</groupId>
                <artifactId>tomcat-embed-jasper</artifactId>
                <scope>provided</scope>
            </dependency>
    
    org.apache.tomcat.embed 汤姆卡特·贾斯珀 假如
  • 这个替代方法对我来说很有效,它可以获取应用程序上下文。

    错误是否应该说pageContext不能解析为类型而不是内容?还有,我猜你在用Tomcat?结帐,@kmb385抱歉是的,你是正确的,我将编辑我添加的内容(我更新了Maven,刷新了项目,清理了项目)但它似乎没有effect@jonnieM我注意到pom.xml文件之间的另一个区别。它似乎删除了
    javax.servlet.jsp.JspException不能解析为类型
    ,但我现在得到
    javax.servlet.jsp.JspWriter不能解析为类型
    JspWriter无法解析为变量
    &
    JspFactory无法解析为类型
    javax.servlet.jsp.PageContext无法解析为类型
    您使用的是什么应用服务器?Tomcat提供了这些库,但我不确定其他应用程序服务器是否提供。尝试从xml中删除为每个依赖项提供的。我尝试删除提供的作用域,但仍然没有效果-tomcat 6是我正在使用的应用程序服务器我得到一个错误
    导入javax.servlet.jsp.PageContent无法解决
    ,当我使用此OK时,除了前面的错误之外。将javax.servlet.jsp.jar放在类路径中。从这里下载我的maven依赖项中确实有这个jar,但没有正确注册,我从构建路径中删除了它,并再次更新了maven项目,这似乎解决了它。感谢您输入的页面上下文,而不是内容:)
    <c:set var="contextPath" value="${pageContext.request.contextPath}"/>
    
    <link type="text/css" rel="stylesheet" href="${contextPath}/css/yourCssFile.css"/>
    
    <beans xmlns="... xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="...
    http://www.springframework.org/schema/mvc 
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
    
    <mvc:resources mapping="/resources/**" location="/resources/css/" />
    
    <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>
    <bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"/> [Optional]
    <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
        <property name="order" value="0"/>
    </bean>  
    
    This will solve the problem 
    
    <!-- Need this to compile JSP -->
            <dependency>
                <groupId>org.apache.tomcat.embed</groupId>
                <artifactId>tomcat-embed-jasper</artifactId>
                <scope>provided</scope>
            </dependency>