学习下 java servlet 你就知道怎么做了
/**
* 短信回调 servlet,此 servlet是由第三方短信平台调用,用于第三方平台推送发送结果或者发送报告。
* create by @author lms 2018.04.27
*/
package hs.oa.servlet;
import hs.oa.tool.SmsMgrTool;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import ms.core.tool.StrTool;
public class SmsAckServlet extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = 20000L;
/**
* Constructor of the object.
*/
public SmsAckServlet() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
private void doResponse(int opt, HttpServletRequest request, HttpServletResponse response){
try{
String ret = SmsMgrTool.ackReport(opt, request);
if (!StrTool.isBlankStr(ret)){
response.setContentType("text/html;charset=utf-8");
PrintWriter out = response.getWriter();
out.write(ret);
out.flush();
out.close();
}
}catch(Exception e){
e.printStackTrace();
}
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doResponse(0,request,response);
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doResponse(1,request,response);
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}