1. Configuration instructions:
+ = Editor: Eclipse (Java EE IDE)
= = database: MySQL (MySQL Workbench for database management, with MySQL connector/j connection)
= = Server: Tomcat
2. Eclipse is the green version, do not need to install, can put some plug-ins for easy development
3. Tomcat needs to configure the environment variable, which is the bin directory, which has scripts for operations such as startup and shutdown on various platforms. Do not open it manually or there may be port conflicts when eclipse is running
4. Eclipse needs to add the Tomcat server as instructed when creating a new Dynamic Web site
5. MySQL connector/j will have a jar file under C/program file (/x86) after installation to import the project's build path. Otherwise, you may get an error when you import JDBC driver.
Note The password is set when MySQL is installed, as well as the default font (utf-8 default collation is selected)
Template code: (Create the corresponding schema and table in the database first)
<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding= "Utf-8"%><%@ pageImport= "Com.mysql.jdbc.Driver"%><%@ pageImport= "Java.sql.*"%><%//driver nameString drivername = "Com.mysql.jdbc.Driver";//Database user nameString uname = "root";//PasswordString Upassword = "Roger";//Table nameString tableName = "Person";//Database nameString dbName = "Roger";//URLString url = "jdbc:mysql://localhost/" +dbname+ "? user=" +uname+ "&password=" +Upassword; Class.forName ("Com.mysql.jdbc.Driver"). newinstance (); Connection Conn=drivermanager.getconnection (URL); Statement stmt=conn.createstatement (); String SQL= "SELECT * from" +TableName; ResultSet RS=stmt.executequery (SQL);//get the number of columns in a datasetResultSetMetaData RSMD =Rs.getmetadata ();intIcolumns =Rsmd.getcolumncount (); Out.print ("<table border=1><tr>"); for(inti=1;i<icolumns;++i) {Out.print ("<td>" +rsmd.getcatalogname (i) + "</td>");} Out.print ("</tr>"); while(Rs.next ()) {Out.print ("<tr>"); for(inti=1;i<icolumns;++i) {Out.print ("<td>" +rs.getstring (i) + "</td>"); } out.print ("</tr>");} Out.print ("</table>"); Out.print ("Success!"); Rs.close (); Stmt.close (); Conn.close ();%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >Results:
The code above may have other problems, at least the whole process is going through!
Building a JSP development environment under Windows