主要的jsp文件:
student.jsp
1 <%@ page import="java.io.*" %> 2 <%@ page import="java.sql.*" %> 3 <%@ page import="java.util.*" %> 4 <%@ page language="java" contentType="text/html; charset=utf-8" 5 pageEncoding="utf-8"%> 6 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 7 <html> 8 <head> 9 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 10 <title>Student_Infomation</title> 11 </head> 12 <body> 13 <center> 14 <h1>STUDENTS_INFOMATIONS</h1> 15 <hr> 16 <% 17 try{ 18 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 19 Connection con; 20 Statement stmt; 21 ResultSet rs; 22 String url="jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=D:/student.accdb"; 23 24 con=DriverManager.getConnection(url); 25 stmt=con.createStatement(); 26 rs = stmt.executeQuery("SELECT * FROM student"); 27 %> 28 <table border=1> 29 <tr> 30 <td>StudentNum</td> 31 <td>StudentName</td> 32 <td>StudentAge</td> 33 <td>StudentAddr</td> 34 <td>StudentSch</td> 35 <td>StudentMaj</td> 36 <td>StudentScore</td> 37 </tr> 38 <% 39 while(rs.next()){ 40 out.println("<tr>"); 41 out.println("<td>"+rs.getInt("num")+"</td>"); 42 out.println("<td>"+rs.getString("name")+"</td>"); 43 out.println("<td>"+rs.getInt("age")+"</td>"); 44 out.println("<td>"+rs.getString("fromw")+"</td>"); 45 out.println("<td>"+rs.getString("school")+"</td>"); 46 out.println("<td>"+rs.getString("major")+"</td>"); 47 out.println("<td>"+rs.getInt("score")+"</td>"); 48 out.println("</tr>"); 49 } 50 51 rs.close(); 52 stmt.close(); 53 con.close(); 54 }catch(Exception e){out.println(e.getMessage());} 55 %> 56 </table> 57 </center> 58 </body> 59 </html>
修改web.xml
WEB.xml
1 <?xml version="1.0" encoding="utf-8"?> 2 3 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xmlns="http://java.sun.com/xml/ns/javaee" 5 xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 6 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> 7 8 <display-name>Student</display-name> 9 <description> 10 Query the information of students from Access Database 11 </description> 12 </web-app>