zoukankan      html  css  js  c++  java
  • JSP第八次作业

    <%@ page language="java" contentType="text/html; charset=utf-8"
        pageEncoding="utf-8"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>Insert title here</title>
    <style type="text/css">
        #div{ 
            color: red;
        }
    </style>
    </head>
    <body>
        <form action="writeServlet">
            标题:<input type="text" name="title"><br>
            内容:<input type="text" name="content"><br>
            发送至:<input type="text" name="sendto"><br>
            <input type="submit" value="确认发送"> 
        </form>
        <div id="div">
            <%=request.getSession().getAttribute("xx")==null?"":request.getSession().getAttribute("xx")%>
        </div>
        <%request.getSession().removeAttribute("xx"); %>
    </body>
    </html>
    package servlet;
    
    import java.io.IOException;
    import java.util.Date;
    
    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 org.springframework.jdbc.core.JdbcTemplate;
    
    import Utils.JDBCUtils;
    import domain.Email;
    
    /**
     * Servlet implementation class writeServlet
     */
    @WebServlet("/writeServlet")
    public class writeServlet extends HttpServlet {
        private static final long serialVersionUID = 1L;
           
        /**
         * @see HttpServlet#HttpServlet()
         */
        public writeServlet() {
            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
            request.setCharacterEncoding("utf-8");
            String title = request.getParameter("title");
            String content = request.getParameter("content");
            String sendto = request.getParameter("sendto");
            Email email = new Email();
            email.setTitle(title);
            email.setContent(content);
            email.setSendto(sendto);
            email.setSend_date(new Date());
            JdbcTemplate template=new JdbcTemplate(JDBCUtils.getDataSource());
            String sql="insert into email value (null,?,?,?,?,?)";
            template.update(sql,email.getTitle(),email.getContent(),email.getSendto(),"1",email.getSend_date());
            request.getSession().setAttribute("xx", "发送成功");
            request.getRequestDispatcher("/write_email.jsp").forward(request, response);
        }
    
        /**
         * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
         */
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            // TODO Auto-generated method stub
            doGet(request, response);
        }
    
    }

  • 相关阅读:
    (01)Docker简介
    Gym-101242B:Branch Assignment(最短路,四边形不等式优化DP)
    2019牛客暑期多校训练营(第三场)G: Removing Stones(启发式分治)
    POJ
    高维前缀和
    HDU
    BZOJ
    HDU
    POJ
    Gym-100648B: Hie with the Pie(状态DP)
  • 原文地址:https://www.cnblogs.com/522-simple/p/12875613.html
Copyright © 2011-2022 走看看