JSP中利用数据源对象建立数据库连接
配置程序的运行目录与JDBC数据源:
<Context path="/test" docBase="F:\JSPLesson\test" reloadable="true">
<Resource name="jdbc/bookstore" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="root" password="123456"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/bookstore?autoReconnect=true"/>
</Context>
JSP中通过如下方式得到数据库连接:
<%
Context ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/bookstore");
Connection conn = ds.getConnection();
%>
相关文档:
index.jsp:
<html>
<head>
<title>The News</title>
</head>
<body>
<h1> Latest News</h1>
<table>
<tr>
<td><h3><%@include file="items/news1.jsp" %></h3></td>
</tr>
<tr>
<td> ......
复选框的使用及JSP对数据的处理
<!--
Description: HTML表单复选框及JSP处理测试
Author: pxzl
Date: 2009-08-05 15:12:43
-->
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%
String[] cheArray1=request.getParameterValues("chkbox1");
String[] cheArray2=req ......
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<%@ page contentType="text/html; charset=gb2312" language="java"
import="java.sql.*"%>
<%
/*********************
&nb ......