<html>
<head>
</head>
<body>
<script type="text/javascript">
function login(){
document.loginform.submit();
}
<!--
tmpDate=new Date();
date=tmpDate.getDate();
month=tmpDate.getMonth()+1;
year=tmpDate.getYear();
document.write(year);
document.write("年");
document.write(month);
document.write("月");
document.write(date);
document.write("日");
//-->
</script>
你好,欢迎来到新闻中心。
<%!
String odbcQuery;
int pageSize=3;
int pageCount=0;
%>
<%
String query_type=request.getParameter("select");
if(query_type==null) query_type="标题";
String query_content=request.getParameter("query");
if(query_content==null) query_content="";
if(query_content!=null&&query_type!=null)
{
query_content=(new String(query_content.getBytes("ISO-8859-1"))).trim();
query_type=new String(query_type.getBytes("ISO-8859-1"));
if(query_type.equals("1"))
odbcQuery="Select News_id,News_date,News_type,News_title from mynews New_title like'%"+query_content+"%'order by News_DESC";
else if(query_type.equals("2"))
odbcQuery="Select News_id,News_date,News_type,News_title from mynews New_date like'%"+query_content+"%'order by News_DESC";
else
odbcQuery="Select News_id,News_date,News_type,News_title from mynews New_type like'%"+query_content+"%'order by News_DESC";
}
else
odbcQuery="Select * from mynews";
try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
}catch(ClassNotFoundException e){out.println(123);}
try{
Connection con=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=mynews","sa","123");
Statement sql=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs;
rs=sql.executeQuery(odbcQuery);
rs.last();
int lastRow=rs.getRow();
pageCount=(lastRow%pageSize==0)?(lastRow/pageSize):(lastRow/pageSize+1);
int showPage=1;
%>
<table bordercolor="#ff0000" width="420">
<form name="form1" method="get" action="view_news.jsp">
<tr bgcolor="#99CCCC">
<td>新闻查询</td>
<td>
<select name="select">
<option value="1" selected>标题</option>
<option value="2" >日期</option>
<option value="3" >类型</option>
</select>
</td>
<td>
<div>
<input name="query" type="text" id="query" size="14"/>
</div>
</td>
<td>
<input type="submit" name="Submit" value="查询"/>
</td>
</tr>
</form>
<form name="form2" method="get" action="">
<tr bgcolor="#CCCCCC">
<td bgcolor="#99CCCC">输入页码
</td>
<td bgcolor="#99CCCC"><input name="showPage" type="text" id="showPage" Size="4"/>
</td>
<input type="hidden" name="select" size=2 maxlength=10 class=smallInput value="<%=query_type %>"/>
<input type="hidden" name="query" size=2 maxlength=10 class=smallInput value="<%=query_content %>"/>
<td colspan="3" bgcolor="#99CCCC"><div align="center">
<input type="submit" name="Submit3" value="提交"/>
<%String integer=request.getParameter("showPage");
if(integer==null){
integer="1";
}
try{
showPage=Integer.parseInt(integer);
}
catch(NumberFormatException e){
showPage=1;
}
if(showPage<=1){
showPage=1;
}
if(showPage>=pageCount){
showPage=pageCount;
}
if(showPage>1){
%>
<a href="?showPage=<%=showPage-1 %>">1</a>
<%
}
if(showPage<pageCount){%>
<a href="?showPage=<%=showPage+1 %>">2</a>
<%
}
%>
共<%=pageCount %>页 目前第<%=showPage%>页
</div>
</td>
</tr>
</form>
</table>
<table border="0" cellspacing="1" bgcolor="#663399" width="420">
<tr bgcolor="#3399ff">
<td width="25%"><div align="center">入库序号</div></td>
<td width="25%"><div align="center">入库时间</div></td>
<td width="25%"><div align="center">新闻类型</div></td>
<td width="25%"><div align="center">新闻标题</div></td>
</tr>
<%
int position=(showPage-1)*pageSize+1;
rs.absolute(position);
for(int i=1;i<=pageSize;i++){
%>
<tr bgcolor="#ffffff" width="512">
<td width="25%" height="22"><%=rs.getString(2)%><div align="center"></div></td>
<td width="25%"><%=rs.getString(3)%><div align="center"></div></td>
<td width="25%"><%=rs.getString(4)%><div align="center"></div></td>
<td width="25%"><%=rs.getInt(5)%><div align="center"></div></td>
</tr>
<%
rs.next();
}con.close();
}catch(SQLException e1){out.println(123);}
%>
</table>
</body>
</html>
6 个解决方案
#1
这是asp吗?
#2
jsp啊..
#3
语法是jsp,用法是asp
不看你代码了,贴异常吧
#4
我看书打的啊.
#5
什么异常啊
#6
现在哪有人写页面把后台也进去的
#1
这是asp吗?
#2
jsp啊..
#3
语法是jsp,用法是asp
不看你代码了,贴异常吧
#4
我看书打的啊.
#5
什么异常啊
#6
现在哪有人写页面把后台也进去的