📄 newslist.jsp
字号:
<%@ page contentType="text/html; charset=GB2312"
language="java"
import = "java.util.*, java.text.*,java.sql.*,MyBean.charsetConvert"
%>
<jsp:useBean id="dbc" scope="session" class="MyBean.dbcon" />
<%
String menu="";
try
{
menu = request.getParameter("menu");
}
catch(Exception ex)
{
menu="update";
}
if (menu==null || menu =="")
{
menu="update";
}
if(menu.equals("del"))
{
String tmp;
tmp="delete from newsinfo where newsid="+request.getParameter("newsid");
if(dbc.executeUpdate(tmp)>=0)
out.println("<script>alert('信息删除成功!');location.href='newslist.jsp'</script>");
else
out.println("<script>alert('信息删除失败!');location.href='newslist.jsp'</script>");
}
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<LINK href="Style.css" type=text/css rel=stylesheet>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
}
-->
</style>
<script language="javascript">
function del(url,id)
{
if (confirm('\n是否确认删除该条新闻?'))
location=url+"?menu=del&newsid="+id
}
</script>
</head>
<body>
<a href="newsadd.jsp">-添加新闻-</a>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td valign="top" >
<table width="99%" cellpadding=0 cellspacing=0 align=center>
<form name=form method=post action="newslist.jsp">
<tr><td align=left>
新闻类型:
<select name="TypeID" id="TypeID">
<option value="0">所有</option>
<%
ResultSet rs=dbc.executeQuery("select * from typeinfo ");
while(rs.next())
{
out.println("<option value="+rs.getString("newstypeid")+">+"+rs.getString("newstype")+"</option>");
}
%>
</select>
<script language="javascript">
var dd,s,i,m,d;
dd = new Date();
s=dd.getYear();
m=dd.getMonth();
d=dd.getDate();
document.write ("<select name=syear>");
for(i=s;i>=s-10;i--)
{
document.write("<option value="+i);
if(i==s)
document.write (" selected");
document.write (">"+i+"</option>");
}
document.write ("</select>年");
document.write ("<select name=smonth>");
for(i=1;i<=12;i++)
{
document.write("<option value="+i);
if(i==m+1)
document.write (" selected");
document.write (">"+(i)+"</option>");
}
document.write ("</select>月");
document.write ("<select name=sday>");
for(i=1;i<=31;i++)
{
document.write("<option value="+i);
if(i==d)
document.write (" selected");
document.write (">"+i+"</option>");
}
document.write ("</select>日");
document.write ("--");
document.write ("<select name=eyear>");
for(i=s;i>=s-10;i--)
{
document.write("<option value="+i);
if(i==s)
document.write (" selected");
document.write (">"+i+"</option>");
}
document.write ("</select>年");
document.write ("<select name=emonth>");
for(i=1;i<=12;i++)
{
document.write("<option value="+(i));
if(i==m+1)
document.write (" selected");
document.write (">"+(i)+"</option>");
}
document.write ("</select>月");
document.write ("<select name=eday>");
for(i=1;i<=31;i++)
{
document.write("<option value="+i);
if(i==d)
document.write (" selected");
document.write (">"+i+"</option>");
}
document.write ("</select>日");
</script>
新闻标题:<input type=text size=12 name=key>
<input type=submit name=submit value="查询">
</td></tr>
</form>
</table>
<table width="99%" border="1" align="center" cellpadding="2" bordercolor="#C0C0C0" bordercolorlight="#C0C0C0" bordercolordark="#FFFFFF" bgcolor="#EEEEEE">
<tr height=22>
<td width="50%" align=center>新闻标题</tD>
<td width="15%" align=center>新闻类型</tD>
<td width="20%" align=center>添加日期</tD>
<td width="15%" align=center>操作</tD>
</tr>
<%
String strSQL=" ";
String key="";
String smonth=request.getParameter("smonth");
String sday=request.getParameter("sday");
String emonth=request.getParameter("emonth");
String eday=request.getParameter("eday");
if (eday!=null )
{
int tint;
tint=Integer.parseInt(eday);
tint++;
eday=String.valueOf(tint);
}
String sdate="";
String edate="";
key=request.getParameter("key");
if(request.getParameter("syear")!=null && request.getParameter("smonth")!=null && request.getParameter("sday")!=null)
{
sdate=request.getParameter("syear");
if(smonth.length()<2)
sdate=sdate + "0" + smonth;
else
sdate=sdate+smonth;
if(sday.length()<2)
sdate=sdate + "0" + sday;
else
sdate=sdate+sday;
}
if(request.getParameter("eyear")!=null && request.getParameter("emonth")!=null && request.getParameter("eday")!=null)
{
edate=request.getParameter("eyear");
if(emonth.length()<2)
edate=edate + "0" + emonth;
else
edate=edate+emonth;
if(eday.length()<2)
edate=edate + "0" + eday;
else
edate=edate+eday;
}
if(key!=null && key!="")
strSQL=strSQL+ " and title like '%"+key+"%'";
if(sdate!=null && sdate!="" && edate!=null && edate!="")
strSQL=strSQL + " and (convert(varchar(10),uptime,20) >='" + sdate +"' and convert(varchar(10),uptime,20) <= '" + edate + "')";
String tmp="";
tmp="select a.newsid,a.title,b.newstype,a.uptime from newsinfo a,typeinfo b "
+" where 1=1 and a.newstypeid=b.newstypeid "
+strSQL + " order by uptime desc ";
tmp=charsetConvert.parseChinese(tmp);
ResultSet newsRs=dbc.executeQuery(tmp);
String newsid="";
String newstype="";
String uptime="";
while(newsRs.next())
{
System.out.println("2");
newsid=newsRs.getString("newsid").toString();
System.out.println("3");
out.println("<tr height=22>");
out.println("<td>·"+newsRs.getString("title").toString()+"</td>");
newstype = newsRs.getString("newstype").toString();
uptime = newsRs.getString("uptime").toString();
out.println("<td align=center>"+newstype+"</td>");
System.out.println("5");
out.println("<td align=center>"+uptime+"</td>");
%>
<td align=center><a href="newsmodify.jsp?newsid=<%=newsid%>">修改</a> <a href="javascript:del('newslist.jsp',<%=newsid%>)">删除</a></td></tr>
<%
}
%>
</table></td>
</tr>
</table>
<a href="newsadd.jsp">-添加新闻-</a>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -