package jp.ac.kcska.questionsystem.categorymanager.horizon; import java.io.IOException; import java.sql.SQLException; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import jp.ac.kcska.questionsystem.ExcuteDatabase; public class AddCategoryServlet extends HttpServlet { private static final long serialVersionUID = 1L; @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("UTF-8"); resp.setContentType("text/html; charset=UTF-8"); String categoryname = req.getParameter("categoryname"); String valid = req.getParameter("valid"); ExcuteDatabase excuteDatabase = new ExcuteDatabase(); String sql = "INSERT INTO MST_CATEGORY (categoryname,valid) VALUES ('" + categoryname + "'," + valid + ")"; try { excuteDatabase.excuteInsert(sql); } catch (SQLException e) { e.printStackTrace(); } RequestDispatcher dispatcher = req.getRequestDispatcher("/CategoryManager"); dispatcher.forward(req, resp); } }