1,增加
1-1:<body>
<form action="AnnouncementAdd.jsp" method="post">
<h2>新增</h2>
公告标题:<input type="text" name="title"><br/>
公告内容:<input type="text" name="context"><br>
<input type="submit" value="新增">
</form>
1-2:<body>
<%
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
String title=request.getParameter("title");
String context=request.getParameter("context");
AnnouncementDaoImplement ad=new AnnouncementDaoImplement();
Announcement an=new Announcement();
an.setTitle(title);
an.setContext(context);
boolean bn=ad.addAnnouncement(an);
if(bn){
response.sendRedirect("AnnouncementSelectAll.jsp");
}else{
out.print("添加失败了");
out.print("<a href=‘AnnouncementSelectAll.jsp‘>返回原来的页面</a>");
}
%>
</body>
2.删除
<body>
<%
String str=request.getParameter("id");
AnnouncementDaoImplement ad=new AnnouncementDaoImplement();
boolean bn=ad.deleteAnnouncement(Integer.parseInt(str));
if(bn){
response.sendRedirect("AnnouncementSelectAll.jsp");
}else{
out.print("删除失败了");
out.print("<a href=‘AnnouncementSelectAll.jsp‘>回到原来的页面</a>");
}
%>
</body>
3.查询
<body>
<table align="center" width="50%" border="1" cellpadding="1" cellspacing="1">
<tr>
<th>公告编号</th>
<th>公告标题</th>
<th>公告内容</th>
<th>操作</th>
</tr>
<%
AnnouncementDaoImplement ad=new AnnouncementDaoImplement();
List<Announcement> list= ad.selectAll();
for(Announcement an:list){
%>
<tr align="center">
<td><%=an.getId()%></td>
<td><%=an.getTitle()%></td>
<td><%=an.getContext() %></td>
<td><a href="AnnouncementDel.jsp?id=<%=an.getId()%>">删除</a>||
<a href="AnnouncementUpdate.jsp?id=<%=an.getId()%>">修改</a></td>
</tr>
<%} %>
</table>
<h3><a href="AnnouncementAdd.html">新增</a></h3>
</body>
4.修改
4-1 <body>
<%
int in=Integer.parseInt(request.getParameter("id"));
AnnouncementDaoImplement an=new AnnouncementDaoImplement();
Announcement ann=an.selectAnnouncement(in);
if(ann instanceof Announcement){%>
<form action="AnnouncementUpdate2.jsp" method="post">
<p>公告编号:<input type="text" size="60" name="upid" value="<%=ann.getId()%>" readonly="readonly"></p>
<p>公告标题:<input type="text" size="60" name="title" value="<%=ann.getTitle()%>"</p>
<p>公告内容:<input type="text" size="60"name="context" value="<%=ann.getContext()%>"</p>
<p><input type="submit" value="修改"/></p>
</form>
<% }else{
out.print("删除失败了");
out.print("<a href=‘AnnouncementSelectAll.jsp‘>回到原来的页面</a>");
}
%>
</body>
4-2
<body>
<%
String id=request.getParameter("upid");
String title=request.getParameter("title");
String context=request.getParameter("context");
AnnouncementDaoImplement ad=new AnnouncementDaoImplement();
Announcement an=new Announcement();
an.setId(Integer.parseInt(id));
an.setTitle(title);
an.setContext(context);
ad.updateAnnouncement(an);
boolean bn=ad.updateAnnouncement(an);
if(bn){
response.sendRedirect("AnnouncementSelectAll.jsp");
}else{
out.print("修改失败了");
out.print("<a href=‘AnnouncementSelectAll.jsp‘>回到原来的页面</a>");
}
%>
</body>