最近在学习jsp,使用tomcat9和jdk12,第一个jsp程序,编写了一个MyOk.java文件代码如下:
public class MyOk{
public String getTXT(){
String str = "you are success";
return str;
}
}
通过javac编译后生成MyOk.class文件,将该文件拷贝至webapps/testok/WEB-INF/classes目录中,并在testok目录下编写testok.jsp,代码如下:
<%@ page import="MyOk"%>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<p>this is my first jsp program</p>
</body>
</html>
WEB-INF文件中的web.xml文件内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0"
metadata-complete="true">
<display-name>Tomcat Documentation</display-name>
<description>
Tomcat Documentation.
</description>
</web-app>
在浏览器中输入“localhost:8080”可以正常打开tomcat页面,
但输入“localhost:8080/testok/testok.jsp”访问时报出以下错误:
HTTP Status 500 – Internal Server Error
Type 异常报告
消息 Unable to compile class for JSP:
描述 服务器遇到一个意外的情况,阻止它完成请求。
试过百度上的一些方法,但无论怎么设置,都一直出现这个错误,实在没有办法,求教各位大神们,谢谢啦!!