数据库查不到东西,css没有效果


并且页面的css文件似乎没有生效

以下:DAO源码:
public class MessageDAO {
/**
* 分页查询message
* @param page 页码
* @param pageSize 每页长度
* @return
*/
public List<Message> getMessage(int page, int pageSize) {
Connection conn = ConnectionUtils.getConnection();
String sql = "select * from message order by createTime desc limit ?,?"; //limit ?,? : 表示从?条开始,取出?条
PreparedStatement ps = null;
ResultSet rs = null;
List<Message> messages = new ArrayList<>();
try {
ps = conn.prepareStatement(sql);
ps.setInt(1, (page - 1) * pageSize);
ps.setInt(2, pageSize);
rs = ps.executeQuery();
while (rs.next()) {
messages.add(new Message(rs.getLong("id"), rs.getLong("userId"),
rs.getString("username"),rs.getString("title"),
rs.getString("content"),rs.getDate("createTime")));
}
} catch (SQLException e) {
e.printStackTrace();
}finally {
//释放资源
ConnectionUtils.release(rs,ps,conn);
}
return messages;
}
/**
* 计算所有留言的数量
* @return
*/
public int countMessage(){
Connection conn = ConnectionUtils.getConnection();
String sql = "select count(*) table from message";
PreparedStatement ps = null;
ResultSet rs = null;
try {
ps = conn.prepareStatement(sql);
rs = ps.executeQuery();
while (rs.next()){
return rs.getInt("table");
}
} catch (SQLException e) {
e.printStackTrace();
}finally {
ConnectionUtils.release(rs,ps,conn);
}
return 0;
}
}
以下:connectUtils工具类
/**
* 数据库操作公共类
*/
public class ConnectionUtils {
private static String url = "jdbc:mysql://localhost:3306/message_board";
private static String user = "root";
private static String password = "rootroot";
static {
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
System.out.println("加载驱动失败!未找到驱动程序。");
e.printStackTrace();
}
}
/**
* 获得数据库连接
* @return
*/
public static Connection getConnection() {
try {
return DriverManager.getConnection(url,user,password);
} catch (Exception e) {
System.out.println("创建连接失败!");
e.printStackTrace();
}
return null;
}
/**
* 释放数据库资源
* @param rs ResultSet
* @param ps PreparedStatement
* @param conn Connection
*/
public static void release(ResultSet rs, PreparedStatement ps, Connection conn) {
if (rs != null) {
try {
rs.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (ps != null) {
try {
ps.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (conn != null) {
try {
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
}
}
}
以下:老师提供的message_list.jsp文件的截图:

正在回答 回答被采纳积分+1
css没有效果应该是相对路径加载失败了,这里建议同学绝对路径再试试,如:
href="${pageContext.request.contextPath}/css/index.css">或者同学写一下basePath相关代码
<% String basePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath()+"/"; %>
在引入css路径前加上<%=basePath %>
祝:学习愉快~
- 参与学习 人
- 提交作业 277 份
- 解答问题 4297 个
Java数据库开发的必备技能,从流行的MySQL数据库开始,到Java原生的数据库管理接口JDBC的使用,再到常用的数据持久化框架MyBatis,让你向Java工程师的目标又迈进了一步!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星