Added, deleted, modified, and queried jsp pages.

Source: Internet
Author: User

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>

 

  

  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.