<%
String action=request.getParameter("action");
if(action!=null&&action.equals("quit")){
session.setAttribute("strSystemID","");
}
String loginName=(String)session.getAttribute("strSystemID");
if(loginName!=null&&!loginName.equals("")){
response.sendRedirect("main.jsp");
return;
}
%>
<script language="javascript" src="../include/appClient.js"></script>
<body onload="javascript:document.getElementById('strSystemID').focus();">
<form action="checkLogin.jsp" method="post">
username:
<input type="text" name="strSystemID" size="30" valid="true">
UserPass:
<input type="password" name="strSystemPass" valid="true" size="30">
<input type="submit" value="submit">
</form>
</body>
<%@ page contentType="text/html;charSet=GBK"%>
<%@ page import="java.sql.*,java.util.*"%>
<jsp:useBean id="systemBean" class="cn.com.huangls.enterprise.system" scope="page"/>
<jsp:useBean id="adminBean" class="cn.com.huangls.enterprise.admin" scope="page"/>
<%
//初始化环境,用于接收参数值
systemBean.init(request,response);
String strSystemID=systemBean.getParaStr("strSystemID",100,"");
String strSystemPass=systemBean.getParaStr("strSystemPass",100,"");
adminBean.setSystemID(systemBean.toGBK(strSystemID));
adminBean.setSystemPass(systemBean.toGBK(strSystemPass));
boolean flag=adminBean.isAdmin();
if(!flag){
String msg= " <script language=javascript>"+
" alert('对不起,用户名或密码错误');history.back(-1);"+
" </script>";
out.println(msg);
return;
}
//保存该对象信息
session.setAttribute("strSystemID",strSystemID);
response.sendRedirect("main.jsp");
%>
package cn.com.huangls.enterprise;
import java.io.*;
import java.util.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class system extends HttpServlet
{
private String sysConfigFile="config";
private HttpServletRequest request=null;
private HttpServletResponse response=null;
public void init(HttpServletRequest req,HttpServletResponse res) throws Exception{
this.request=req;
this.response=res;
}
public String getParaStr(String obj,int len,String defaultValue){
String tempValue="";
if(request==null) return "";
tempValue=request.getParameter(obj);
if(tempValue==null){
tempValue="";
}
tempValue=tempValue.trim();
if(tempValue.equals("")){
tempValue=defaultValue;
}
return tempValue;
}
public Connection getConnection() throws Exception{
Connection conn=null;
String driver=getProperties("jdbc.driver");
String server=getProperties("jdbc.server");
String user=getProperties("jdbc.user");
String password=getProperties("jdbc.password");
try{
Class.forName(driver);
}catch(Exception ex){
throw new Exception(getProperties("error","NoFindDriver"));
}
try{
conn=DriverManager.getConnection(server,user,password);
}catch(Exception ex){
throw new Exception(getProperties("error","ConnectError")+ex.toString());
}
return conn;
}
public ArrayList executeQuery(String strSQL) throws Exception{
ResultSet res1=null;
Statement comm=null;
Connection tempConn=null;
ArrayList arrayList=new ArrayList();
try{
tempConn=getConnection();
if(tempConn!=null){
comm=tempConn.createStatement();
res1=comm.executeQuery(strSQL);
ResultSetMetaData myStr=res1.getMetaData();
while(res1.next()){
Hashtable b=new Hashtable();
for(int i=1;i<=myStr.getColumnCount();i++){
String name=myStr.getColumnName(i);
String value=res1.getString(i);
System.out.println(name);
System.out.println(value);
b.put(name,value);
}
arrayList.add(b);
}
}
}catch(Exception ex){
throw new Exception(ex.toString());
}finally{
res1.close();
comm.close();
tempConn.close();
}
return arrayList;
}
public String getProperties(String field){
return getProperties(sysConfigFile,field);
}
public String getProperties(String file,String field){
String tempValue="";
try{
ResourceBundle bundle=ResourceBundle.getBundle(file);
tempValue=bundle.getString(field);
}catch(Exception ex){
System.out.println("Error:"+ex.toString());
}
return tempValue;
}
//转换成中文
public String toGBK(String tempValue){
String defaultValue=tempValue;
try{
defaultValue=new String(defaultValue.getBytes("iso8859-1"),"GBK");
}catch(Exception ex){
System.out.println(ex.toString());
}
return defaultValue;
}
String action=request.getParameter("action");
if(action!=null&&action.equals("quit")){
session.setAttribute("strSystemID","");
}
String loginName=(String)session.getAttribute("strSystemID");
if(loginName!=null&&!loginName.equals("")){
response.sendRedirect("main.jsp");
return;
}
%>
<script language="javascript" src="../include/appClient.js"></script>
<body onload="javascript:document.getElementById('strSystemID').focus();">
<form action="checkLogin.jsp" method="post">
username:
<input type="text" name="strSystemID" size="30" valid="true">
UserPass:
<input type="password" name="strSystemPass" valid="true" size="30">
<input type="submit" value="submit">
</form>
</body>
<%@ page contentType="text/html;charSet=GBK"%>
<%@ page import="java.sql.*,java.util.*"%>
<jsp:useBean id="systemBean" class="cn.com.huangls.enterprise.system" scope="page"/>
<jsp:useBean id="adminBean" class="cn.com.huangls.enterprise.admin" scope="page"/>
<%
//初始化环境,用于接收参数值
systemBean.init(request,response);
String strSystemID=systemBean.getParaStr("strSystemID",100,"");
String strSystemPass=systemBean.getParaStr("strSystemPass",100,"");
adminBean.setSystemID(systemBean.toGBK(strSystemID));
adminBean.setSystemPass(systemBean.toGBK(strSystemPass));
boolean flag=adminBean.isAdmin();
if(!flag){
String msg= " <script language=javascript>"+
" alert('对不起,用户名或密码错误');history.back(-1);"+
" </script>";
out.println(msg);
return;
}
//保存该对象信息
session.setAttribute("strSystemID",strSystemID);
response.sendRedirect("main.jsp");
%>
package cn.com.huangls.enterprise;
import java.io.*;
import java.util.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class system extends HttpServlet
{
private String sysConfigFile="config";
private HttpServletRequest request=null;
private HttpServletResponse response=null;
public void init(HttpServletRequest req,HttpServletResponse res) throws Exception{
this.request=req;
this.response=res;
}
public String getParaStr(String obj,int len,String defaultValue){
String tempValue="";
if(request==null) return "";
tempValue=request.getParameter(obj);
if(tempValue==null){
tempValue="";
}
tempValue=tempValue.trim();
if(tempValue.equals("")){
tempValue=defaultValue;
}
return tempValue;
}
public Connection getConnection() throws Exception{
Connection conn=null;
String driver=getProperties("jdbc.driver");
String server=getProperties("jdbc.server");
String user=getProperties("jdbc.user");
String password=getProperties("jdbc.password");
try{
Class.forName(driver);
}catch(Exception ex){
throw new Exception(getProperties("error","NoFindDriver"));
}
try{
conn=DriverManager.getConnection(server,user,password);
}catch(Exception ex){
throw new Exception(getProperties("error","ConnectError")+ex.toString());
}
return conn;
}
public ArrayList executeQuery(String strSQL) throws Exception{
ResultSet res1=null;
Statement comm=null;
Connection tempConn=null;
ArrayList arrayList=new ArrayList();
try{
tempConn=getConnection();
if(tempConn!=null){
comm=tempConn.createStatement();
res1=comm.executeQuery(strSQL);
ResultSetMetaData myStr=res1.getMetaData();
while(res1.next()){
Hashtable b=new Hashtable();
for(int i=1;i<=myStr.getColumnCount();i++){
String name=myStr.getColumnName(i);
String value=res1.getString(i);
System.out.println(name);
System.out.println(value);
b.put(name,value);
}
arrayList.add(b);
}
}
}catch(Exception ex){
throw new Exception(ex.toString());
}finally{
res1.close();
comm.close();
tempConn.close();
}
return arrayList;
}
public String getProperties(String field){
return getProperties(sysConfigFile,field);
}
public String getProperties(String file,String field){
String tempValue="";
try{
ResourceBundle bundle=ResourceBundle.getBundle(file);
tempValue=bundle.getString(field);
}catch(Exception ex){
System.out.println("Error:"+ex.toString());
}
return tempValue;
}
//转换成中文
public String toGBK(String tempValue){
String defaultValue=tempValue;
try{
defaultValue=new String(defaultValue.getBytes("iso8859-1"),"GBK");
}catch(Exception ex){
System.out.println(ex.toString());
}
return defaultValue;
}









