• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

JSP 08

开发技术 diligentman 2周前 (05-12) 21次浏览

JSP 08

JSP 08

<%@ page language="java"contentType="text/html; charset=utf-8"pageEncoding="utf-8"%> <!DOCTYPE html> <html> <head> <metacharset="utf-8"> <title>Insert title here</title> <styletype="text/css">#div{color:red; } </style> </head> <body> <formaction="writeServlet">标题:<inputtype="text"name="title"><br>内容:<inputtype="text"name="content"><br>发送至:<inputtype="text"name="sendto"><br> <inputtype="submit"value="确认发送"> </form> <divid="div"> <%=request.getSession().getAttribute("xx")==null?"":request.getSession().getAttribute("xx")%> </div> <%request.getSession().removeAttribute("xx");%> </body> </html>

packageservlet;importjava.io.IOException;importjava.util.Date;importjavax.servlet.ServletException;importjavax.servlet.annotation.WebServlet;importjavax.servlet.http.HttpServlet;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;importorg.springframework.jdbc.core.JdbcTemplate;importUtils.JDBCUtils;importdomain.Email;/*** Servlet implementation class writeServlet*/@WebServlet("/writeServlet")public class writeServlet extendsHttpServlet {private static final long serialVersionUID = 1L;/***@seeHttpServlet#HttpServlet()*/ publicwriteServlet() {super();//TODO Auto-generated constructor stub }/***@seeHttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)*/ protected void doGet(HttpServletRequest request, HttpServletResponse response) throwsServletException, 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= newEmail(); email.setTitle(title); email.setContent(content); email.setSendto(sendto); email.setSend_date(newDate()); JdbcTemplate template=newJdbcTemplate(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); }/***@seeHttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)*/ protected void doPost(HttpServletRequest request, HttpServletResponse response) throwsServletException, IOException {//TODO Auto-generated method stub doGet(request, response); } }

 

JSP 08

原文地址:https://www.cnblogs.com/yanzhen108/p/12875424.html


程序员灯塔 , 版权所有
转载请注明原文链接:https://www.wangt.cc/2020/05/jsp-08/
喜欢 (0)