JspException和PageContext无法解析 [英] JspException and PageContext cannot be resolved
问题描述
这是对访问资源的问题的跟进在Spring MVC应用的JSP页面中 感谢@ kmb385,我能够解决该问题,但是现在我的JSP文件中出现以下eclipse错误 javax.servlet.jsp.JspException无法解析为一种类型 和
This is a follow up to a question on accessing resources in jsp page of spring mvc app Thanks to @kmb385 I was able to resolve that problem but now I get the following eclipse errors in my JSP file javax.servlet.jsp.JspException cannot be resolved to a type and
javax.servlet.jsp.PageContext无法解析为类型
javax.servlet.jsp.PageContext cannot be resolved to a type
如kmb385所建议,这是我的控制器:
as suggest by kmb385, here is my controller:
@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页面,以防万一:
and here is my index.jsp page just in case:
<%@ 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验证器中禁用它来解决此问题的解决方案",但是除非您有正当的理由,否则请不要提出此建议.我宁愿正确地纠正此问题
I have come across "solutions" to this by disabling it in the JSP validator but Please do not suggest this unless you can give a legitimate reason. I would rather correct this issue properly
任何帮助表示赞赏
更新: 按@ kmb385的要求构建路径屏幕抓取
UPDATE: Build path screen grab as requested by @kmb385
推荐答案
尝试将pom.xml中的servlet-api
依赖项设置为提供.这个jar可能与提供的servlet-api.jar的tomcat冲突.
Try setting the servlet-api
dependency in your pom.xml to provided. This jar maybe conflicting with the tomcat provided servlet-api.jar.
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
还请确保包含jsp-api依赖项,并再次按提供的方式进行设置:
Also be sure to include the jsp-api dependency, once again set as provided:
<!-- Servlet -->
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.3</version>
<scope>provided</scope>
</dependency>
通过右键单击项目>属性,确保所有maven依赖项都已用于构建项目.在部署程序集"选项卡上,单击添加"按钮,然后单击"Java构建路径条目",然后单击"Maven依赖关系",最后单击完成".
Make sure all of your maven dependencies are being used to build the project by right clicking your project > Properties. On the deployment assembly tab click the add button, then Java Build Path Entries, then Maven Dependencies and finally Finish.
您可能还需要将maven依赖项添加到构建路径.右键单击您的项目> Maven>更新项目配置.
You may also need to add your maven dependencies to the build path. Right click your project > Maven > Update Project Configuration.
这篇关于JspException和PageContext无法解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!