JSP第十三周作业

package doservlet;
 
import java.io.IOException;
 
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import dao.MsgDao;
 
/**
 * Servlet implementation class dodelete
 */
@WebServlet("/dodelete")
public class dodelete extends HttpServlet {
    private static final long serialVersionUID = 1L;
        
    /**
     * @see HttpServlet#HttpServlet()
     */
    public dodelete() {
        super();
        // TODO Auto-generated constructor stub
    }
 
    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doPost(request, response);
    }
 
    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        int id=Integer.parseInt(request.getParameter("id"));
        MsgDao md=new MsgDao();
        md.delMail(id);
        response.sendRedirect("main.jsp");
    }
 
}


package doservlet;
 
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import dao.UsersDao;
 
/**
 * Servlet implementation class dologin
 */
@WebServlet("/dologin")
public class dologin extends HttpServlet {
    private static final long serialVersionUID = 1L;
        
    /**
     * @see HttpServlet#HttpServlet()
     */
    public dologin() {
        super();
        // TODO Auto-generated constructor stub
    }
 
    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doPost(request, response);
    }
 
    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        String uname = request.getParameter("uname");
        String upwd = request.getParameter("upwd");
        UsersDao ud=new UsersDao();
        if(ud.login(uname, upwd)){
            request.getSession().setAttribute("uname", uname);
            request.getRequestDispatcher("main.jsp").forward(request, response);
        }else{
            response.getWriter().print("登陆失败,跳回登陆页");
            response.setHeader("refresh", "5;url=login.jsp");
        }
    }
 
}


package doservlet;
 
import java.io.IOException;
 
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import dao.UsersDao;
 
/**
 * Servlet implementation class doreg
 */
@WebServlet("/doreg")
public class doreg extends HttpServlet {
    private static final long serialVersionUID = 1L;
        
    /**
     * @see HttpServlet#HttpServlet()
     */
    public doreg() {
        super();
        // TODO Auto-generated constructor stub
    }
 
    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doPost(request, response);
    }
 
    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        String uname = request.getParameter("uname");
        String upwd = request.getParameter("upwd");
        UsersDao ud=new UsersDao();
        ud.reg(uname, upwd);
        request.getRequestDispatcher("login.jsp").forward(request, response);
    }
 
}


package doservlet;
 
import java.io.IOException;
 
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import dao.MsgDao;
import entity.Msg;
 
/**
 * Servlet implementation class dowrite
 */
@WebServlet("/dowrite")
public class dowrite extends HttpServlet {
    private static final long serialVersionUID = 1L;
        
    /**
     * @see HttpServlet#HttpServlet()
     */
    public dowrite() {
        super();
        // TODO Auto-generated constructor stub
    }
 
    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doPost(request, response);
    }
 
    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        request.setCharacterEncoding("utf-8");
        String uname=(String)request.getSession().getAttribute("uname");
        String addressee=request.getParameter("addressee");
        String title=request.getParameter("title");
        String content=request.getParameter("content");
         
        Msg m=new Msg();
        m.setContent(content);
        m.setSender(uname);
        m.setAddressee(addressee);
        m.setTitle(title);
         
        MsgDao md=new MsgDao();
        md.addMsg(m);
         
        response.getWriter().print("发送成功!!!");
        response.setHeader("refresh", "5;url=main.jsp");
    }
 
}
posted @ 2022-05-28 22:06  葛广瑞  阅读(5)  评论(0编辑  收藏  举报