2.20 Javaweb 总结

每日总结打卡:内容包括:日期、每日关键字、每日总结、坚持天数(自动计数,显示上次天数)、连续最长天数。

实现网页输入数据录入数据库

今日未完成,录入目前进度

 

 

package com;

import java.sql.Connection;
import java.sql.PreparedStatement;

public class Interface {
    public boolean add( model){
        String riqi =model.riqi();
        String keyword =model.keyword();
        String zongjie =model.zongjie();
        String inday =model.inday();
        String maxday =model.maxday();

        Util db=new Util();
        try {
            String sql="INSERT INTO day(riqi,keyword,zongjie,inday,maxday) VALUES (?,?,?,?,?)";
            Connection conn=db.getCon();
            PreparedStatement ps=conn.prepareStatement(sql);
            ps.setString(1, riqi);
            ps.setString(2, keyword);
            ps.setString(3, zongjie);
            ps.setString(4, inday);
            ps.setString(5, maxday);
            ps.executeUpdate();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return true;

    }
}
package com;

public class model {
    private String riqi;
    private String keyword;
    private String zongjie;
    private String inday;
    private static String maxday;
    public String getRiqi() {
        return riqi;
    }

    public void setRiqi(String riqi) {
        this.riqi = riqi;
    }

    public String getKeyword() {
        return keyword;
    }

    public void setKeyword(String keyword) {
        this.keyword = keyword;
    }

    public String getZongjie() {
        return zongjie;
    }

    public void setZongjie(String zongjie) {
        this.zongjie = zongjie;
    }

    public String getInday() {
        return inday;
    }

    public void setInday(String inday) {
        this.inday = inday;
    }

    public String getMaxday() {
        return maxday;
    }

    public void setMaxday(String maxday) {
        this.maxday = maxday;
    }
}

  

package com;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Util {
    private String url="jdbc:mysql://localhost:3306/db-jsp";
    private String user="root";
    private String password="123456";
    private String driver="com.mysql.jdbc.Driver";

    public Connection getCon() throws Exception{
        Class.forName(driver);
        Connection con=DriverManager.getConnection(url, user, password);
        return con;

    }


    public static void getClose(Connection con) throws SQLException{
        if(con!=null){
            con.close();
        }

    }

}

  

package com;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class web extends HttpServlet {
    Util db=new Util();

    private static final long serialVersionUID = 1L;

    public PublishServlet() {
        super();
    }


    public void destroy() {
        super.destroy(); // Just puts "destroy" string in log
        // Put your code here
    }


    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {


    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");

        String riqi=request.getParameter("riqi");
        String keyword=request.getParameter("keyword");
        String zongjie=request.getParameter("zongjie");
        String inday=request.getParameter("inday");
        String maxday=request.getParameter("maxday");

        Interface=new Interface();
        Interface.setriqi(riqi);
        literature.setEnglishName(EnglishName);
        literature.setType(Type);
        literature.setAuthor(Author);
        literature.setSource(Source);
        literature.setChineseAbstract(ChineseAbstract);
        literature.setEnglishAbstract(EnglishAbstract);
        literature.setChineseKeyword(ChineseKeyword);
        literature.setEnglishKeyword(EnglishKeyword);
        literature.setReforName(ReforName);
        literature.setIncentive(Incentive);
        literature.setContent(Content);

        LiteratureInterface literatureInter=new LiteratureInterface();
        literatureInter.addLiterature(literature);

        request.getRequestDispatcher("main.jsp").forward(request, response);
    }


    public void init() throws ServletException {
        // Put your code here
    }

}

  

<%--
  Created by IntelliJ IDEA.
  User: 也远
  Date: 2023/2/20
  Time: 17:06
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title>每日总结打卡</title>
  </head>
  <body>
  <form action="PublishServlet" method="post">
    <table>
      <tr>
        <td>日期:</td>
        <td><input type="text" name="riqi" value="${param.riqi}"></td>
      </tr>
      <tr>
        <td>每日关键字:</td>
        <td><input type="text" name="keyword" value="${param.keyword}"></td>
      </tr>
      <tr>
        <td>每日总结:</td>
        <td><input type="text" name="zongjie" value="${param.zongjie}"></td>
      </tr>
      <tr>
        <td>坚持天数:</td>
        <td><input type="text" name="inday" value="${param.inday}"></td>
      </tr>
      <tr>
        <td>连续最长天数:</td>
        <td><input type="text" name="maxday" value="${param.maxday}"></td>
      </tr>
      </tr>
      <tr>
        <td>
          <input type="submit" value="提交">
        </td>
      </tr>
    </table>
  </form>
  </body>
</html>

  

 

posted @ 2023-02-20 22:20  方自然  阅读(100)  评论(0)    收藏  举报