Application has two applications, 1 is a map, and the code is as follows
1 <body>2 <%! 3 int i=1; 4 %>5 <%6 application.setattribute ("Count", string.valueof (i++)); 7 %>8 <%=application.getattribute ("Count")%>9 </body>
Use SetAttribute and getattribute.
2 is to read the Web. XML configuration information, the code is as follows: first the web. XML code:
1<!--configuration Welcome page-2<welcome-file-list>3<welcome-file>index.jsp</welcome-file>4</welcome-file-list>5<!--Drive-6<context-param>7<param-name>driver</param-name>8<param-value>com.mysql.jdbc.Driver</param-value>9</context-param>Ten<context-param> One<!--URL-- A<param-name>url</param-name> -<param-value>jdbc:mysql://localhost:3306/house</param-value> -</context-param> the<!--connect users-- -<context-param> -<param-name>user</param-name> -<param-value>root</param-value> +</context-param> -<!--connection Password-- +<context-param> A<param-name>pwd</param-name> at<param-value>123456</param-value> -</context-param>
Then the JSP code:
<% @pageImport= "Java.sql.ResultSet"%><% @pageImport= "Com.mysql.jdbc.Statement"%><% @pageImport= "Java.sql.DriverManager"%><% @pageImport= "com.mysql.jdbc.Connection"%><%@ page language= "java" contenttype= "text/html; CHARSET=GBK "pageencoding= "GBK"%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >String Driver= Application.getinitparameter ("Driver"); String URL= Application.getinitparameter ("url"); String User= Application.getinitparameter ("User"); String pwd= Application.getinitparameter ("pwd"); //Load DriverClass.forName (driver); //Establish a connectionConnection conn =(Connection) drivermanager.getconnection (URL, user, pwd); //Create statementStatement stm =(Statement) conn.createstatement (); //Execute QueryResultSet rs = stm.executequery ("Select username,pwd from User"); %> <table border= "1" width= "> <%"//Traverse Results while(Rs.next ()) {%> <tr> <td><%=rs.getstring (1)%></td> <td><%=rs.getstring (2)%></td> </tr> <% } %> </table></body> Jsp-application Apps