<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<html>
<head>
<title>hello</title>
</head>
<body>
Hello World!<br/>
<%
out.println("Your IP address is " + request.getRemoteAddr());
%>
</body>
</html>
在使用IDEA初次建立WEB应用时,JSP页面的out对象不能正常使用。
解决办法:
在建立的WEB应用的pom.xml中添加Servlet的依赖(注意:要对应版本关系,关系不一致,可能导致不能正常使用)
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.2</version>
<scope>provided</scope>
</dependency>
添加依赖完成后,使用Tomcat容器启动访问,得到正常的页面显示。