The querystudent.jsp code is as follows
<%@ page language="Java"Contenttype="text/html; charset=gb2312"pageencoding="UTF-8"%><! DOCTYPE HTML Public"-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD">"border-right: #89d4f8 1px solid;border-Top: #89d4f8 1px solid; Border-left: #89d4f8 1px solid"cellspacing=0cellpadding= -Align=center bgcolor= #ffffff border=0> <tbody> <tr> <td height= -> Add student information </td> </tr> <tr> <td height=1bgcolor= #89d4f8 > </td> </tr> </tbody> </table> <!--click button Search <form name=messages method="Post"action="after_querystudent.jsp"> <table width=" -"align="Center"Border="0"> <tr> <td width=" the"></td> <td><input type="Submit"Value="Find all student information"></td> </tr> </table> </form></body>After_querystudent.jsp page Code
<%@ page language= "Java"Import= "Java.util.*"Import= "Com.mysql.jdbc.Driver"Import= "Java.sql.*"ContentType= "text/html;charset=gb2312"pageencoding= "UTF-8"%><%String Path=Request.getcontextpath (); String BasePath= Request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/"; %><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >Connection Conn; Statement Stat; //set the URL of the connection, where student is the database nameString url= "Jdbc:mysql://localhost:3306/student"; //I am using the free install version of MySQL, User: root, Password: ZhangweijieString username= "Root"; String Password= "Zhangweijie"; Try{ //registering the JDBC driverClass.forName ("Com.mysql.jdbc.Driver"); } Catch(ClassNotFoundException ex) {out.println ("Driver not Found!" "); } //Open a database connectionconn=drivermanager.getconnection (Url,username,password); Try{stat=conn.createstatement (); //If there is a data table with the same name, delete it firstResultSet result=stat.executequery ("select * from Student_info;"); //Draw a table to display the dataOut.println ("<table border>"); Out.println ("<TR><TD colspan=3 align=center> Student Information </td></tr>"); Out.println ("<tr>"); Out.println ("<td width=150> </td>"); Out.println ("<TD width=150> name </td>"); Out.println ("<TD width=150> Contact Phone </td>"); Out.println ("</tr>"); while(Result.next ()) {//reads the query results and displaysOut.println ("<tr>"); Out.println ("<td>" +result.getint (1) + "</td>"); Out.println ("<td>" +result.getstring (2) + "</td>"); Out.println ("<td>" +result.getstring (3) + "</td>"); Out.println ("</tr>"); } } Catch(SQLException ex) {out.println ("Data table operation failed!"); } finally{conn.close (); } %></body>