码迷,mamicode.com
首页 > 其他好文 > 详细

响应自己写的报错信息

时间:2016-08-24 01:04:06      阅读:111      评论:0      收藏:0      [点我收藏+]

标签:

import java.io.IOException;
import java.io.PrintWriter;

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 SendErrorServlet
*/
@WebServlet("/SendErrorServlet")
public class SendErrorServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
* @see HttpServlet#HttpServlet()
*/
public SendErrorServlet() {
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
doPost(request, response);
}

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub

response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
// 获取输入流
PrintWriter out =response.getWriter();
// 设置响应状态码以及响应状态信息
response.sendError(response.SC_NOT_FOUND,"对不起 亲爱的 找不到你了!");
}

}

响应自己写的报错信息

标签:

原文地址:http://www.cnblogs.com/sdswl/p/5801232.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!