我们所需要的软件
http://www.netbeans.org/kb/50/quickstart-gui.html
ide开发工具netbeans http;//www.netbeans.org
http://www.netbeans.info/downloads/download.php?type=5.0
mysql jdbc 驱动
http://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-3.0.17-ga.zip/from/http://mirror.mysql-partners-jp.biz/
mysql就不用我说了,搜索一下就可以。
<%@page contentType="text/html"%>
<%@page pageEncoding="gb2312"%>
<%@page import="java.sql.*"%>
<%@page import="java.util.*"%>
<%@page import="java.io.*"%>
<%--
The taglib directive below imports the JSTL library. If you uncomment it,
you must also add the JSTL library to the project. The Add Library... action
on Libraries node in Projects view can be used to add the JSTL 1.1 library.
--%>
<%--
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
--%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>我的第一个jsp程序</title>
</head>
<body>
<form method="post" action="GetServlet.do">
请输入您的名字: <input type="text" name="username">
<input type="submit" value="查询" name="submit">
</form>
<%!
String host="localhost";
String database="cendy";
String user="root";
String pass="";
%>
<%
java.sql.Connection sqlConn;
java.sql.Statement sqlStmt;
java.sql.ResultSet sqlRst;
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
sqlConn= java.sql.DriverManager.getConnection("jdbc:mysql://"+host+"/"+database,user,pass);
sqlStmt=sqlConn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY);
String sqlQuery="select count(*) from username";
sqlRst=sqlStmt.executeQuery(sqlQuery);
sqlRst.next();
int count=sqlRst.getInt(1);
sqlQuery="select * from username;";
sqlRst=sqlStmt.executeQuery(sqlQuery);
%>
一共<%=count%>条记录
<table border="0" width="35%" bordercolorlight="#CC99FF" cellpadding="1" bordercolordark="#FFFFFF" cellspacing="1">
<tr align="center" bgcolor="#F4FCFF">
<td width="18%">ID</td>
<td width="49%">用户名</td>
<td width="33%">密码</td>
</tr>
<% while (sqlRst.next()) {%>
<tr align="center" bgcolor="#F0F0F0">
<td width="18%"><%=sqlRst.getString("id")%></td>
<td width="49%"><%=sqlRst.getString("username")%></td>
<td width="33%"><%=sqlRst.getString("passwd")%></td>
</tr>
<% } %>
</table>
</body>
<%
sqlRst.close();
sqlStmt.close ();
sqlConn.close();
%>
<%--
This example uses JSTL, uncomment the taglib directive above.
To test, display the page like this: index.jsp?sayHello=true&name=Murphy
--%>
<%--
<c:if test="${param.sayHello}">
<!-- Let's welcome the user ${param.name} -->
Hello ${param.name}!
</c:if>
--%>
</body>
</html>