Home > front end >  The Servlet is what input text output are question mark
The Servlet is what input text output are question mark

Time:04-13

Package com. The action;

/* *
* site
* @ author Administrator
*
*/

import java.io.IOException;
Import the Java. IO. PrintWriter;

The import javax.mail. Servlet. ServletException;
The import javax.mail. Servlet. HTTP. HttpServlet;
The import javax.mail. Servlet. HTTP. It;
The import javax.mail. Servlet. HTTP. HttpServletResponse;
The import javax.mail. Servlet. HTTP. HttpSession;

The import com. Beans. AfficheBean;
The import com. Beans. SystemBean;
The import com. Util. Constant;
The import com. Util. Filter;

Public class AfficheServlet extends the HttpServlet {

/* *
* Constructor of the object.
*/
Public AfficheServlet () {
super();
}

/* *
* Destruction of the servlet. & lt; Br>
*/
Public void destroy () {
Super. Destroy ();//Just puts "destroy" string in the log
//Put your code here
}

/* *
* The doGet method of The servlet. & lt; Br>
*
* This method is called when a form has its tag value method equals to get.
*
* @ param request the request send by the client to the server
* @ param response the response the send by the server to the client
* @ throws ServletException if an error occurred
* @ throws IOException if an error occurred
*/
Public void doGet (it request, HttpServletResponse response)
Throws ServletException, IOException {

The doPost (request, response);
}

/* *
* The doPost method of The servlet. & lt; Br>
*
* This method is called when a form has its tag value method equals to post.
*
* @ param request the request send by the client to the server
* @ param response the response the send by the server to the client
* @ throws ServletException if an error occurred
* @ throws IOException if an error occurred
*/
Public void doPost (it request, HttpServletResponse response)
Throws ServletException, IOException {

The response. SetContentType (Constant. CONTENTTYPE);
PrintWriter out=response.getWriter();
Request. SetCharacterEncoding (Constant. CHARACTERENCODING);
String sysdir=new SystemBean (.) getDir ();
The HttpSession session=request. GetSession ();
Try {
String username2=(String) session. The getAttribute (" user ");
If (username2==null) {
Request. GetRequestDispatcher (" error. JSP "). The forward (request, response);
}
The else {
AfficheBean AfficheBean=new AfficheBean ();
String method=request. The getParameter (" method "). The trim ();
If (method. The equals (" addAffiche ")) {//increase announcement
String title=Filter. EscapeHTMLTags (request. The getParameter (" title "). The trim ());
The String content=Filter. EscapeHTMLTags (request. The getParameter (" content "). The trim ());
String adder=username2;
String ifhide=Filter. EscapeHTMLTags (request. The getParameter (" ifhide "). The trim ());
Int flag=afficheBean. AddAffiche (title, content, adder, ifhide);
If (flag==Constant. SUCCESS) {
Request. SetAttribute (" message ", "operation success!" );
Request. GetRequestDispatcher (sysdir + "/affiche/index. The JSP"). The forward (request, response);
}
The else {
Request. SetAttribute (" message ", "in the system maintenance, please try again later." );
Request. GetRequestDispatcher (sysdir + "/affiche/index. The JSP"). The forward (request, response);
}
}
Else if (method) equals (" editAffiche ")) {//modify bulletin
String id=Filter. EscapeHTMLTags (request. The getParameter (" id "). The trim ());
String title=Filter. EscapeHTMLTags (request. The getParameter (" title "). The trim ());
The String content=Filter. EscapeHTMLTags (request. The getParameter (" content "). The trim ());
String adder=username2;
String ifhide=Filter. EscapeHTMLTags (request. The getParameter (" ifhide "). The trim ());
Int flag=afficheBean. UpdateAffiche (Integer. The parseInt (id), the title and content, adder, ifhide);
If (flag==Constant. SUCCESS) {
Request. SetAttribute (" message ", "operation success!" );
Request. GetRequestDispatcher (sysdir + "/affiche/index. The JSP"). The forward (request, response);
}
The else {
Request. SetAttribute (" message ", "in the system maintenance, please try again later." );
Request. GetRequestDispatcher (sysdir + "/affiche/index. The JSP"). The forward (request, response);
}
}
Else if (method) equals (" hideAffiche ")) {
String id=Filter. EscapeHTMLTags (request. The getParameter (" id "). The trim ());
Int flag=afficheBean. HideAffiche (Integer. The parseInt (id));
If (flag==Constant. SUCCESS) {
Request. GetRequestDispatcher (sysdir + "/affiche/index. The JSP"). The forward (request, response);
}
The else {
Request. SetAttribute (" message ", "system maintenance, please try again later." );
Request. GetRequestDispatcher (sysdir + "/affiche/index. The JSP"). The forward (request, response);
}
}
Else if (method) equals (" delaffiche ")) {//delete announcement
String check []=request. GetParameterValues (" checkit ");
If (check==null) {
Request. SetAttribute (" message ", "please choose to delete records!" );
Request. GetRequestDispatcher (sysdir + "/affiche/index. The JSP"). The forward (request, response);
}
The else {
Int id=new int [] [check length].
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related