一。配置web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>3</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>3</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>CASFilter</filter-name>
<filter-class>edu.yale.its.tp.cas.client.filter.CASFilter</filter-class>
<init-param>
<param-name>edu.yale.its.tp.cas.client.filter.loginUrl</param-name>
<param-value>https://jdeps:8444/cas/login</param-value>
</init-param>
<init-param>
<param-name>edu.yale.its.tp.cas.client.filter.validateUrl</param-name>
<param-value>https://jdeps:8444/cas/proxyValidate</param-value>
</init-param>
<init-param>
<param-name>edu.yale.its.tp.cas.client.filter.serverName</param-name>
<param-value>jdeps:9090</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CASFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
二。修改登录页面
<%@ page language="java" import="java.util.*" %>
<%@ page contentType="text/html; charset=gb2312" %>
<%@ page import="com.mysql.jdbc.Driver" %>
<%@ page import="java.sql.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
This is my JSP page. <br>
<table border="0" cellpadding="0" cellspacing="0" width="748" class="centertable">
<tr>
<td>
<table border='0' cellspacing='0' cellpadding='0'>
<tr>
<td width='598' valign='top' class='content'>
<h1><font face="微软雅黑" size="4">Please Login</font></h1>
<form name="LoginActionForm" action="login.do" id="LoginActionForm" method="post"><font face="微软雅黑"><font size="3"><strong>
Username:</strong> <input type="text" name="num" size="20" id="num" ><br><strong>
Password: </strong><input type="password" name="a" size="22" id="a">
<input type="hidden" id="goto" value='<%=session.getAttribute("edu.yale.its.tp.cas.client.filter.user")%>' ">
</font><br><br></font><blockquote><blockquote><font size="3" face="微软雅黑"><input type="submit" id="loginInfo" value="Login"></font></blockquote></blockquote>
</form>
</td>
</tr>
</table>
</td>
</tr>
</table>
<%
//String name=session.getAttribute("edu.yale.its.tp.cas.client.filter.user").toString();
//out.println(name);
//String driverName="com.mysql.jdbc.Driver";
//String userName="root";
//String userPasswd="admin";
//String dbName="db";
String tableName="db";
//String url="jdbc:mysql://192.168.132.16:3306/"+dbName+"?user="+userName+"&password="+userPasswd;
//Class.forName("com.mysql.jdbc.Driver").newInstance();
//Connection connection=DriverManager.getConnection(url);
//Statement statement = connection.createStatement();
//String sql="SELECT * FROM "+tableName;
//out.println(sql);
//ResultSet rs = statement.executeQuery(sql);
//ResultSetMetaData rmeta = rs.getMetaData();
//while(rs.next()) {
//String name=request.getParameter("name");
//out.println(name);
//out.print("22");
//name=rs.getString(1);
//out.print(name);
//String password=rs.getString(2);
//}
//rs.close();
//statement.close();
//connection.close();
%>
<!--
//alert(name);
//document.getElementById('login').submit();
</script>
-->
<%
//驱动程序名
String id=session.getAttribute("edu.yale.its.tp.cas.client.filter.user").toString();
String driverName="com.mysql.jdbc.Driver";
//数据库用户名
String userName="root";
//密码
String userPasswd="admin";
//数据库名
String dbName="db";
String name="111";
String password="";
//表名
String tableName="db";
//联结字符串
String url="jdbc:mysql://192.168.132.16:3306/"+dbName+"?user="+userName+"&password="+userPasswd;
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection=DriverManager.getConnection(url);
Statement statement = connection.createStatement();
String sql="SELECT * FROM "+tableName;
String where=" where id='"+id+"'";
sql=sql.concat(where);
out.println(sql);
ResultSet rs = statement.executeQuery(sql);
//获得数据结果集合
ResultSetMetaData rmeta = rs.getMetaData();
int numColumns=rmeta.getColumnCount();
// 输出每一个数据值
out.print("id");
out.print("|");
out.print("num");
out.print("<br>");
while(rs.next()) {
out.print(rs.getString(2)+" ");
out.print("|");
out.print(rs.getString(3));
out.print("<br>");
name=rs.getString(2);
password=rs.getString(3);
}
out.print("<br>");
out.print("数据库操作成功,恭喜你");
rs.close();
statement.close();
connection.close();
out.print(session.getAttribute("edu.yale.its.tp.cas.client.filter.user"));
//LoginActionForm loginform = (LoginActionForm) actionForm;
// String username = loginform.setNum(name);
// String userpass = loginform.setA(password);
%>
<script>
var num="<%=name%>";
var a="<%=password%>";
document.getElementById('num').value=num;
document.getElementById('a').value=a;
document.getElementById('LoginActionForm').submit();
</script>
</body>
</html>