Reputation: 31
A new JSP project was created ,after the start of the tomcat, the browser only displays the source code, how can I deal with this situation?
I just want to create a java web project. It's my project structure:
Upvotes: 2
Views: 2869
Reputation: 84
are you sure to added bellow maven dependencies (jar files) to your project?
<!-- Need this to compile JSP -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<!-- JSP API -->
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.2</version>
</dependency>
<!-- Servlet API -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
Upvotes: 1
Reputation: 14572
Here is the code of a JSP created by Netbeans for a Web App project. It works fine.
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>
It looks like in the langage attribute, there is a space before java
, can't say if this is the reason, can't say if it is needed.
I did test your code, Netbeans tell me that the language attribute isn't valide, remove the space to correct this. It works fine
<%@page contentType="text/html; charset=UTF-8" language="java"%>
<html>
<head>
<title>JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>
Upvotes: 0
Reputation: 84
try to add
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
after page tag, maybe works correctly
Upvotes: 0