2019.9.5 curriculum design

A day to complete the task

   Write Servlet, JDBC write up feeling better, but always present error 500, feel there is a relationship web.xml servlet and servlet-mapping of multiple configuration jsp feel there is some problem.

   Registration code is as follows, that is, to log into a select sql statement

package com.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class Regist
 */
@WebServlet("/Regist")
public class Regist extends HttpServlet {
    private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Regist() {
        super();
        // TODO Auto-generated constructor stub
    }
    public void init(ServletConfig config) throws ServletException {
        // TODO Auto-generated method stub
        super.init(config);
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();
        Connection con;
        PreparedStatement pstmt = null;
        String logname = request.getParameter("logname1").trim();
        String password = request.getParameter("password1").trim();
        String uri = "jdbc:mysql://localhost:3306/my?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false";
        try {
            con = DriverManager.getConnection(uri,"root","123456");
            String sql = "insert into test(logname,password) values(?,?)";
            pstmt.setString(1,logname);
            pstmt.setString(2, password);
            pstmt.executeUpdate();
            out.print("ok");
        }catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    /**
     * @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);
    }

}

Second, the next day's program

   LAN tomorrow put that somehow, came back to ask what the cloud server.

Third, Daily Summary

   ①Servlet not a good school, ah,

   ② finally put voice to insert into, but the navigation API can not support changing the navigation page

   ③ can almost get gitlab and reported

 

Guess you like

Origin www.cnblogs.com/RecKono/p/11469435.html