Added, deleted, modified, and queried jsp pages.
1. Add
1-1:<Body>
<Form action = "AnnouncementAdd. jsp" method = "post">
<H2> New
Announcement title: <input type = "text" name = "title"> <br/>
Announcement content: <input type = "text" name = "context"> <br>
<Input type = "submit" value = "add">
</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 ();
If (bn ){
Response. sendRedirect ("AnnouncementSelectAll. jsp ");
} Else {
Out. print ("failed to add ");
Out. print ("<a href = 'announcementselectall. jsp '> return to the original page </a> ");
}
%>
</Body>
2. Delete
<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 ("deletion failed ");
Out. print ("<a href = 'announcementselectall. jsp '> return to the original page </a> ");
}
%>
</Body>
3. Query
<Body>
<Table align = "center" width = "50%" border = "1" cellpadding = "1" cellspacing = "1">
<Tr>
<Th> Announcement No. </th>
<Th> announcement title </th>
<Th> announcement content </th>
<Th> operation </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 () %> "> Delete </a> |
<A href = "AnnouncementUpdate. jsp? Id = <% = an. getId () %> "> modify </a> </td>
</Tr>
<% }%>
</Table>
<H3> <a href = "AnnouncementAdd.html"> added </a>
</Body>
4. Modify
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> Announcement No.: <input type = "text" size = "60" name = "upid" value = "<% = ann. getId () %> "readonly =" readonly "> </p>
<P> announcement title: <input type = "text" size = "60" name = "title" value = "<% = ann. getTitle () %> "</p>
<P> announcement content: <input type = "text" size = "60" name = "context" value = "<% = ann. getContext () %> "</p>
<P> <input type = "submit" value = "modify"/> </p>
</Form>
<%} Else {
Out. print ("deletion failed ");
Out. print ("<a href = 'announcementselectall. jsp '> return to the original page </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 ();
Boolean bn = ad. updateAnnouncement ();
If (bn ){
Response. sendRedirect ("AnnouncementSelectAll. jsp ");
} Else {
Out. print ("modification failed ");
Out. print ("<a href = 'announcementselectall. jsp '> return to the original page </a> ");
}
%>
</Body>