1. A simple JSP test page
File name: index.jsp
The document content is as follows:
<% @ Page ContentType = "Text / HTML"%>
<% @ Page PageEncoding = "UTF-8"%>
<% -
<% -
<% out.println ("Welcome ....");%>
body>
html>
The thick line portion is the added code, and the other is automatically generated for the Java development tool NetBeans, and the output results are shown in the figure:
2. Database connection test page
The file name is: mysql_conn.jsp
The document content is as follows:
<% @ Page ContentType = "Text / HTML"%>
<% @ Page PageEncoding = "UTF-8"%>
<% @ page language = "java" import = "java.sql. *"%>
<%
Java.sql.connection conn;
Java.lang.string strconn;
CONN = NULL;
Try {
Class.Forname ("Org.gjt.mm.mysql.driver"). NewInstance ();
Conn = java.sql.driverManager.getConnection ("JDBC: MySQL: // LocalHost / MySQL", "root", "");
}
Catch (Exception E) {
System.out.println ("Connection Error");
}
Statement Stmt = conn.createstatement ();
ResultSet RS_Result = NULL;
%>
<% -
<% -
<%
Rs_result = stmt.executeQuery ("SELECT * from user"); string name;
While (RS_RESULT.NEXT ()) {
Name = rs_Result.getstring ("User");
%>
<% = Name%>
<%
}
Rs_Result.close ();
Stmt.close ();
CONN.CLOSE ();
%>
body>
html>
Bold is added, and the rest is automatically generated for Java Development Tools NetBeans.
The result is shown in the figure: