java web 跳转不到
初学java web java web 跳转不到相应页面
index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
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>查看所有图书</title>
</head>
<body>
<a href="FindServlet">查看所有图书</a>
</body>
</html>
F
indServlet.java
package com.lyq.bean;
import
java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import
java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import
javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class FindServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException,
IOException {
try {
// 加载数据库驱动,注册到驱动管理器
Class.forName("com.mysql.jdbc.Driver");
// 数据库连接字符串
String url = "jdbc:mysql://localhost:3306/db_database10";
// 数据库用户名
String username = "root";
// 数据库密码
String password = "111";
// 创建Connection连接
Connection conn = DriverManager.getConnection(url,username,password);
// 获取Statement
Statement stmt = conn.createStatement();
// 添加图书信息的SQL语句
String sql = "select * from tb_books";
// 执行查询
ResultSet rs = stmt.executeQuery(sql);
// 实例化List对象
List<Book> list = new ArrayList<Book>();
// 判断光标向后移动,并判断是否有效
while(rs.next()){
// 实例化Book对象
Book book = new Book();
// 对id属性赋值
book.setId(rs.getInt("id"));
// 对name属性赋值
book.setName(rs.getString("name"));
// 对price属性赋值
book.setPrice(rs.getDouble("price"));
// 对bookCount属性赋值
book.setBookCount(rs.getInt("bookCount"));
// 对author属性赋值
book.setAuthor(rs.getString("author"));
// 将图书对象添加到集合中
list.add(book);
}
// 将图书集合放置到request之中
request.setAttribute("list", list);
rs.close(); // 关闭ResultSet
stmt.close(); // 关闭Statement
conn.close(); // 关闭Connection
} catch (
ClassNotFoundException e) {<