<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#a8c7ce">
<tr align="center" height="25" bgcolor="d3eaef">
<td width="5%">
编号
</td>
<td width="10%">
标题
</td>
<td width="23%">
内容
</td>
<td width="10%">
发表日期
</td>
<td width="16%">
基本 *** 作
</td>
</tr>
<%
//获取新闻信息集合,newList是从后台返回来的集合变量
List nList = (List) sessiongetAttribute("newList");
NewsEntity new = null;
if (nListsize() <= 0) {
%>
<tr height="22" bgcolor="#FFFFFF" align="center">
<td colspan="9" align="center">
暂无新闻信息
</td>
</tr>
<%
} else {
for (int i = 0; i < nListsize(); i++) {
new = (NewsEntity) mListget(i);
%>
<tr height="22" bgcolor="#FFFFFF" align="center">
<td>
<%=newgetId() %>
</td>
<td>
<%=newgetTitle() %>
</td>
<td>
<%=newgetContent() %>
</td>
<td>
<%=newtime() %>
</td>
<td>
<a href="MusicServletforward=getNewsDetailById&ID=<%=newgetId()%>" >
<span class="STYLE2">编辑</span> </a> |
<a href="MusicServletforward=doDelNewsById&ID=<%=newgetId()%>"
onclick="return confirm('您确定要删除该条信息吗?');"><span
class="STYLE2">删除</span> </a>
</td>
</tr>
<%
}
}
%>
</table>
在页面中写Java片段 比如:
<%
//驱动程序名
String driverName = "commysqljdbcDriver";
//数据库用户名
String userName = "自己的";
//密码
String userPasswd = "自己的";
//数据库名
String dbName = "自己的";
//表名
String tableName = "自己的";
//联结字符串
String url = "jdbc:mysql://localhost:3306/" + dbName + "user="
+ userName + "&password=" + userPasswd;
ClassforName("commysqljdbcDriver")newInstance();
Connection connection = DriverManagergetConnection(url);
Statement statement = connectioncreateStatement();
String sql = "SELECT FROM " + tableName;
ResultSet rs = statementexecuteQuery(sql);
%>
这种方法并不是很常用,只是页面的相关 *** 作,代码太多,所以中间省略了部分<%
Object userUID=sessiongetAttribute("USERID");
String uid="";
if(userUID!=null)
{
uid=(String)userUID;
}
else
{ responsesendRedirect("/Public/loseSessionjsp");}
try
{
String today=DateUtilsgetInstance()getToday();
String userIP=requestgetRemoteAddr();
String sql="";
String getPage=requestgetParameter("toPage");
sql=cuexchange(requestgetParameter("sql")); if (sql==null||sqlequals("")){
String getDepId="";
String getPoliticalPosition="";
String getTechnicalPosition="";
String getPoliticalLevel="";
String getTechnicalLevel="";
String getDegreeCode="";
String getGrade="";
String getLongevity="";String getAllowance="";
long depId=0;
long degreeCode=0;
long politicalPosition=0;
long technicalPosition=0;
long politicalLevel=0;
long technicalLevel=0;
long grade=0;
long longevity=0;
long allowance=0;
String[] postID=null;
String post="";
String userID="";
String userName="";
String address="";
getDepId=requestgetParameter("depId");
depId=LongparseLong(getDepIdtrim());getDegreeCode=requestgetParameter("degreeCode");
if (getDegreeCode!=null) {
degreeCode=LongparseLong(getDegreeCodetrim());
}
getPoliticalPosition=requestgetParameter("politicalPosition");
if (getPoliticalPosition!=null) {
politicalPosition=LongparseLong(getPoliticalPositiontrim());
}
post=requestgetParameter("post");
if(post!=null&&posttrim()equals("1"))
postID=requestgetParameterValues("dyourlocation");
getTechnicalPosition=requestgetParameter("technicalPosition");if (getTechnicalPosition!=null) {
technicalPosition=LongparseLong(getTechnicalPositiontrim());
}
getPoliticalLevel=requestgetParameter("politicalLevel");if (getPoliticalLevel!=null) {politicalLevel=LongparseLong(getPoliticalLeveltrim());
}getTechnicalLevel=requestgetParameter("technicalLevel");if (getTechnicalLevel!=null) {
technicalLevel=LongparseLong(getTechnicalLeveltrim());
}getGrade=requestgetParameter("grade");if (getGrade!=null) {
grade=LongparseLong(getGradetrim());
}getLongevity=requestgetParameter("longevity");if (getLongevity!=null) {
longevity=LongparseLong(getLongevitytrim());
}getAllowance=requestgetParameter("allowance");
if (getAllowance!=null) {
allowance=LongparseLong(getAllowancetrim());
}
userID=ParamUtilsgetParameter(request,"userID");//用户代码
userName=ParamUtilsgetParameter(request,"userName");
//用户名称
address=ParamUtilsgetParameter(request,"address");
//得到要转入的页面sql="select org_user from org_user,org_detail where org_useruser_id=org_detailuser_id";
if (depId!=0)
{
sql=sql+" and org_userdepartment_id="+depId+"";
}if (userID!=null&&userID!=""){
sql=sql+" and org_useruser_id='"+userID+"'";
}
if (userName!=null&&userName!="")
{
sql=sql+" and org_username like '%"+userName+"%'";
}if (address!=null&&address!="")
{
sql=sql+" and org_useraddress like '%"+address+"%'";
}
if(post!=null&&!posttrim()equals("0"))
{
sql=sql+" and org_detailpost in (";
for(int i=0;i<postIDlength;i++)
{
sql=sql+postID[i];
if(i!=(postIDlength-1))
sql=sql+",";
}
sql=sql+")";
}
if (degreeCode!=0)
{
sql=sql+" and org_detaildegree="+degreeCode+"";
}
if (politicalPosition!=0)
{
sql=sql+" and org_detailpoliticalPosition="+politicalPosition+"";
}
if (technicalPosition!=0)
{
sql=sql+" and org_detailtechnicalPosition="+technicalPosition+"";
}
if (technicalPosition!=0)
{
sql=sql+" and org_detailpoliticalLevel="+politicalLevel+"";
}
if (grade!=0)
{
sql=sql+" and org_detailgrade="+grade+"";
}
if (longevity!=0)
{
sql=sql+" and org_detaillongevity="+longevity+"";
}
if(getAllowance!=null)
{
if (allowance==0||allowance==1)
{
sql=sql+" and org_detailallowance="+allowance+"";
}
}
}
User[] userList =null;
userList=urcomplexSearch(sql);
logaddLog(1,1,1,uid,userIP,uid+"于("+today+")查询员工");int cnt=userListlength;//总记录数
int pageSize=10;//每页显示记录数
int curPage=1;//当前页
int cntPage;//总页数
int m=1; if (cnt>0)
{
if (cnt%pageSize==0)
cntPage=cnt/pageSize;
else
cntPage=cnt/pageSize+1;
}
else
cntPage=0; if (getPage==null)
{
getPage="1";
curPage=1;
}
else
curPage=IntegerparseInt(getPagetrim());
%><form name="thisform" action="userSearchDeljsp" method="post">
<table bgColor="#FFFFFF" border="1" borderColorDark="#ffffff" borderColorLight="#c0c0c0" cellSpacing="0" width="95%" cellpadding="4">
<tr height="25" align="center" bgcolor="#959595">
<td></td>
<td><font color="#FFFFFF">姓名</font></td>
<td><font color="#FFFFFF">性别</font></td>
<td> <font color="#FFFFFF">所在部门</font></td>
<td> <font color="#FFFFFF">办公地址</font></td>
<td><font color="#FFFFFF">联系电话</font></td>
</tr>
<%
int u=1;
for(int i=0;i<cnt;i++)
{
//显示记录的起始位置
int j=(curPage-1)pageSize;
//显示记录的末位置
int k=curPagepageSize;
//只显示page_size条数据
if(m>j&&m<=k)
{
String userId=userList[i]getUserID();
String gender=userList[i]getGender();
String name=userList[i]getName();
String tel=userList[i]getTel();
String useAddress=userList[i]getAddress();
long dep_id=userList[i]getDepID();
String dname=depgetName(userList[i]getDepID());
if(tel==null||telequals("null"))
tel="";
if(useAddress==null||useAddressequals("null"))
useAddress="";
//判断没一行该输出的颜色
if((u%2)==0)
{
outprintln("<tr bgcolor=#D7D7D7 onMouseOver=thisstylebackgroundColor='#fcd4d7'; onMouseOut=if(selectedItem!=thisid){thisstylebackgroundColor='#D7D7D7';}>");
}
else
{
outprintln("<tr onMouseOver=thisstylebackgroundColor='#fcd4d7'; onMouseOut=if(selectedItem!=thisid){thisstylebackgroundColor='#FFFFFF';}>");
}
u++;
%>
<td align=center><input type="checkbox" name="checkbox" id="CHK_+<%=userId%>" value="<%=userId%>"></td>
<td align=center>
<%
long departmentID=urgetDepID(uid);
if(uphaveRight(uid,"USER_COMPLEXQUERY")==true)
{
%>
<a href="userAnalyzejspuserId=<%=userId%>&dep_id=<%=dep_id%>&toPage=<%=curPage%>"><font color="#330099">
<%
}
else if(uphaveRight(uid,"DEPARTMENT_PLATFORM")==true&&dep_id==departmentID)
{
%>
<a href="userAnalyzejspuserId=<%=userId%>&dep_id=<%=dep_id%>&toPage=<%=curPage%>"><font color="#330099">
<%
}
%>
<%=name%></font></a></td>
<%
if(gendertrim()equals("0"))
outprintln("<td align=center>男</td>");
else
outprintln("<td align=center>女</td>");
%>
<td align=center><a href="depintrojspid=<%=dep_id%>&toPage=<%=curPage%>"><font color="#330099"><%=dname%></font></a></td>
<td align=center> <%=useAddress%></td>
<td align=center> <%=tel%></td>
</tr>
<%
}//end if m++;
}//end for
%>
<input type=hidden name="sql" value="<%=sql%>">
<input type=hidden name="page" value="<%=curPage%>">
</table>
</form>
<form name=pageform action="searchActionjsp" method="post">
<table border="0" width="95%">
<tr>
<td align="center">第<%=curPage%>页/共<%=cntPage%>页</td>
<td align="left">
<img name="firstpage" src="/Image/btn_firstpagegif" style="cursor:hand" onclick="pageClick(1)" <%=curPage>1" ":"disabled"%>>
<img name="prepage" src="/Image/btn_prepagegif" style="cursor:hand" onclick="pageClick(<%=curPage-1%>)" <%=curPage>1" ":"disabled"%>>
<img name="nextpage" src="/Image/btn_nextpagegif" style="cursor:hand" onclick="pageClick(<%=curPage+1%>)" <%=curPage<cntPage" ":"disabled"%>>
<img name="lastpage" src="/Image/btn_lastpagegif" style="cursor:hand" onclick="pageClick(<%=cntPage%>)" <%=curPage<cntPage" ":"disabled"%>>
</td>
<td align=left width=55%>
到第<input type="text" name="goPage" size="4">页
<img border="0" src="/Image/icon_searchgif" style="cursor:hand" onclick="aPage()">
</td>
</tr><tr>
<td colspan="3" valign="middle" width="23%" align="right">
<%
if(uphaveRight(uid,"USER_MANAGE")==true)
{
%>
<img border="0" src="/Image/btn_deletegif" style="cursor:hand" onclick="delUser()">
<%}%>
<img border="0" src="/Image/btn_returngif" style="cursor:hand" onclick="back()">
</td>
<input type=hidden name="sql" value="<%=sql%>">
<input type=hidden name="toPage">
</td>
</tr>
</table>
</form>
<br>
<br>
</td>
</tr>
</table>
</td>
</tr>
</table>
<%
}//end else
}//end try
catch(Exception e)
{
outprintln(egetMessage());
}
%>
</td>
</tr>
</table>
点击按钮提交数据,应该是提交给某类的一个方法处理,在这个方法中调用service的某个方法,当要执行这个方法的时候,进入这个方法,在service的这个方法里面有再调用dao的方法,然后进入dao的方法,dao中的方法内,连接数据库处理得到值或集合,然后返回一个值,这个值service得到,同时service的这个方法也有返回值,然后在处理的那个类也就可以得到了,然后给显示出来,
就是每层调用的方法都有返回值,这样一层一层传
ajax的原生态方法即可,
<script type="text/javascript">
var xml>
以上就是关于JSP获取数据库信息全部的内容,包括:JSP获取数据库信息、如何在jsp上查询并显示数据库mysql的数据表、jsp查询数据库代码等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)