java - jsp没有返回任何东西,只是一个空白屏幕
问题描述
下面的 jsp 代码在 Web 浏览器上只返回一个空白屏幕……怎么办?
<%@page import="java.sql.*"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>GAURAV GOSWAMI</title>
<%
try
{
Class.forName("java.sql.DriverManager");
Connection con =(Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/quiz","root","");
Statement stmt = con.createStatement();
String query = "select * from qa";
ResultSet rs = stmt.executeQuery(query);
while(rs.next())
{
%>
<p><br><%rs.getString(0);%></p>
<p><br><%rs.getString(1);%></p>
<p><br><%rs.getString(2);%></p>
<p><br><%rs.getString(3);%></p>
<p><br><%rs.getString(4);%></p>
<%
}
}
catch(Exception e)
{
%>
<br><%e.getMessage();%>
<%
}
%>
</head>
</html>
解决方案
你在头部写正文。
将您的代码移动到正文部分,如下所示:
<%@page import="java.sql.*"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>GAURAV GOSWAMI</title>
</head> <!-- Add this line -->
<body> <!-- Add this line -->
<%
try
{
Class.forName("java.sql.DriverManager");
Connection con =(Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/quiz","root","");
Statement stmt = con.createStatement();
String query = "select * from qa";
ResultSet rs = stmt.executeQuery(query);
while(rs.next())
{
%>
<p><br><%rs.getString(0);%></p>
<p><br><%rs.getString(1);%></p>
<p><br><%rs.getString(2);%></p>
<p><br><%rs.getString(3);%></p>
<p><br><%rs.getString(4);%></p>
<%
}
}
catch(Exception e)
{
%>
<br><%e.getMessage();%>
<%
}
%>
</body> <!-- Add this line -->
<!-- **** </head> *** Remove this line -->
</html>
希望对你有帮助,再见。
PS:我已经标记了<!-- Add this line -->
要更改的行之类的注释。
推荐阅读
- google-cloud-platform - GCP AI 平台管道 CLI
- java - Android:有没有办法在每个布局上应用 android:filterTouchesWhenObscured="true" ?
- html - 使用 flexbox 的响应式投资组合/联系人
- javascript - 返回 LocalStorage Key 中的数组数
- vb.net - 在 Visual Studio 2017 中开发案例工具
- flutter - Flutter FutureBuilder 不会在应用更新时等待
- kubernetes - 无法在 Kubernetes 中连接前端和后端部署
- flutter - Flutter基础相关的多个问题
- python - TypeError:“GetAggregatedReport”对象不支持索引
- flutter - 减小图像的大小会导致部分图像在颤动中丢失