这是关于在spring mvc app的jsp页面中访问资源的问题的后续问题 感谢@ 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;
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的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>
Run Code Online (Sandbox Code Playgroud)
我通过在JSP验证器中禁用它来遇到"解决方案",但除非你能给出合理的理由,否则请不要这样做.我宁愿正确地纠正这个问题
任何帮助赞赏
更新:
按照@kmb385的要求构建路径屏幕抓取

Kev*_*sox 35
尝试servlet-api在pom.xml中设置依赖项以提供.这个jar可能与tomcat提供的servlet-api.jar冲突.
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
还要确保包含jsp-api依赖项,再次设置为提供:
<!-- Servlet -->
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.3</version>
<scope>provided</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
通过右键单击项目>属性,确保所有maven依赖项都用于构建项目.在部署程序集选项卡上,单击"添加"按钮,然后单击"Java构建路径条目",再单击"Maven依赖项",最后单击"完成".
您可能还需要将maven依赖项添加到构建路径.右键单击您的项目> Maven>更新项目配置.
| 归档时间: |
|
| 查看次数: |
53474 次 |
| 最近记录: |