jsp:
<jsp:useBean id="border" scope="page" class= "border.Dbconn"/>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ page import="java.sql.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
PreparedStatement pstmt = null ;
ResultSet rs = null;
Connection conn = border.getConn();
String prompt = "<script language='javascript'>alert('你无权限访问此功能,请与管理员联系!'); window.location='"+basePath+"home.jsp';window.location.target='main';</script>";
String id=request.getParameter("ID");
String sql = "select o.ID as ID,OperateName,Status from UserOperate o left join UserPopedom p on p.OperateID = o.ID and p.UserLevel ="+id;
rs = border.executeSQL(sql);
ResultSet rs2= border.executeSQL("select Description from userrole where RoleID=3");
String account="";
if(rs2!=null)
{
if(rs2.next())
account =rs2.getString("Description");
}
rs2.close();
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title></title>
<link rel="stylesheet" type="text/css" href="<%=basePath%>css/style.css">
<script type="text/javascript" src="<%=basePath%>js/jquery.min.js"></script>
<style type="text/css">
body{background:#fff;padding:20px;}
#authority_submit{float:left;margin-left:241px;margin-top:10px;background:#ccc}
#select{float:left;width:170px;height:20px;margin-top:5px;margin-left:8px;}
#checkbox{float:left;margin-top:2px;margin-left:4px;}
</style>
<script type="text/javascript">
var P = window.parent, E = P.setDialog();
</script>
</head>
<body>
<div>
角色:<%=request.getParameter("roleName")%>
</div>
<div id="adduser_wk">
<%
int j=0;
if(rs!=null)
{
while(rs.next()){
j++;
%>
<%=rs.getString("OperateName") %><input name="ops" type="checkbox" value="<%=rs.getString("ID")%>" <%if("1".equals(rs.getString("Status"))){%>checked<%}%> /><%if(j%4==0){%><br><%}%>
<%
}
}
%>
</div>
<% if("admin".equals(request.getSession().getAttribute("user_name"))){%>
指定可视对讲和监视帐号:<input id="account" value="<%=account%>"/><br/>
<%} %>
<input type="button" value="确定" onclick="send()">
<%
rs.close();
conn.close();
%>
<script>
function send(){
var account="";
if(document.getElementById("account")!=null)
{
account=document.getElementById("account").value;
}
var ID = "<%=id%>";
var ids = "";
$("input[name='ops'][checked=true]").each(function(){ids+=','+this.value ;});//
$.ajax({
type:"POST",
url:"<%=basePath%>editRole.do",
data:{"id":ID,
"account":account,
"ids":ids
},
contentType: "application/x-www-form-urlencoded; charset=utf-8",
success:function(data){
alert(data);
//history.go(0);
top.frames['aaa'].frames['main'].document.location.reload();
},
error:function(data){
alert("修改失败");
}
});
}
</script>
</body>
</html>
数据库的Dbconn类:
package border;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.springside.modules.utils.SystemGlobals;
public class Dbconn {
public Dbconn()
{
}
private Connection conn = null;
private ResultSet rs = null;
private static final String drivername="com.mysql.jdbc.Driver";
private static String URLr;
public Connection getConn(){
if(URLr==null)
{
String server = SystemGlobals.getValue("mysqlip");
String port = SystemGlobals.getValue("mysqlport");
String db = SystemGlobals.getValue("database");
String user = SystemGlobals.getValue("mysqluser");
String pass = SystemGlobals.getValue("mysqlpassword");
URLr="jdbc:mysql://"+server+":"+port+"/"+db+"?useUnicode=true&characterEncoding=utf-8&user="+user+"&password="+pass;
}
try {
Class.forName(drivername).newInstance();
conn = DriverManager.getConnection(URLr);
} catch (Exception e) {
}
return conn ;
}
public ResultSet executeSQL(String str) {
try{
Statement stmt = conn.createStatement();
rs = stmt.executeQuery(str);
}
catch(Exception e){
e.printStackTrace();
}
return rs;
}
}