JSP 08
2021-03-08 09:27
标签:cep imp ndt super prot http att protected isp JSP 08 标签:cep imp ndt super prot http att protected isp 原文地址:https://www.cnblogs.com/yanzhen108/p/12875424.html@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
DOCTYPE html>
html>
head>
meta charset="utf-8">
title>Insert title heretitle>
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);
}
}
上一篇:常用HTML+CSS属性