【发布时间】:2023-03-09 15:41:01
【问题描述】:
我的 jsp 页面有问题。 首先,我创建了一个数据库,表图像具有一些属性 imageID、imageTitle、imageURL、imageStyle 继续我创建一个新的jsp页面 这是代码:
<%@page import="java.sql.*"%>
<%@page import="com.mysql.jdbc.Connection"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
try {
String _URL = "jdbc:mysql://localhost/slider";
String _USER = "root";
String _PASS = "password";
java.sql.Connection connection = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection(_URL, _USER, _PASS);
//if(!connection.isClosed())
//out.println("Successfully connected to " + "MySQL server using TCP/IP...");
//connection.close();
int img_id = 1;
ResultSet rs = null;
PreparedStatement pstmt = null;
String strslide = "";
strslide += "<div class=\"panel\">";
strslide += "<div class=\"container\"><div class=\"wt-rotator\">";
strslide +="<a href=\"#\"></a>";
strslide += "<div class=\"desc\"></div><div class=\"preloader\"></div><div class=\"c-panel\"><div class=\"buttons\">";
strslide+="<div class=\"prev-btn\"></div>";
strslide+="<div class=\"play-btn\"></div>";
strslide+="<div class=\"next-btn\"></div>";
strslide+="</div>";
strslide +="<div class=\"thumbnails\">";
strslide += "<ul>";
try {
pstmt = connection.prepareStatement("select * from image where id = @id");
pstmt.setInt(1, img_id);
rs = pstmt.executeQuery();
if(rs.next()) {
// some code at here
}
}
catch(Exception ex){
ex.printStackTrace();
}
}catch(Exception ex){
out.println("Unable to connect to database"+ex);
}
%>
</body>
</html>
我不知道如何使用 jsp 代码将图像显示到页面中,我编写了一些理想的代码。我创建到 mysql 的连接,之后我选择查询以从表图像中获取一些属性。在我想在我的代码中提供属性以在页面中显示图像之后。
在这里我有一个 css 文件,一个 js 文件,一些图片在路径 images/...
谢谢!
【问题讨论】:
标签: java jquery html mysql jsp