Joke Collection Website - Blessing messages - How does java create a simple http interface?

How does java create a simple http interface?

1. modify the web.xml file

& lt! Simulate HTTP calls and write one. Artoz. Artoz. Artoz. Action. Order. Sending SMS operation; Import com.atoz.util.springcontextutil;

The public class SmsHTTPServer extends HTTP servlet {private static final long serialversionuid =1l;

The public void doget (http servlet request, HttpServletResponse response) throws ServletException, ioexception {response. setcontenttype ("text/html; charset = utf-8“); request . setcharacterencoding(“utf-8“); response . setcharacterencoding(“utf-8“); PrintWriter out = response . getwriter(); string content = request . getparameter(“content“); //String content = new string (request.getparameter ("content")). getBytes(“iso-8859- 1“)、“utf-8“); string mobiles = request . getparameter(“mobiles“); string business code = request . getparameter(“business code“); string business type = request . getparameter(“business type“); if(content = = null | |“。 equals(content)| | content . length()& lt; = 0){ system。 Out.println ("HTTP call failed, parameter content cannot be empty, program exits"); } else if(mobiles = = null | |“。 equals(mobiles)| | mobiles . length()& lt; = 0){ system。 Out.println ("HTTP call failed, parameter mobiles cannot be empty, and the program exits"); } else {/* SendSMSServiceImpl send = new SendSMSServiceImpl(); */SendSMSAction sendSms =(SendSMSAction)springcontextutil . get bean(“sendSms“); SendSms.sendSms (content, mobile phone, service code, service type); System. out.println ("-HTTP call succeeded-"); } out . close(); }

Public void dopost (HTTP Servlet Request, HttpServletResponse) throws ServletException, IOException {this.doGet (request, response); } }

3. Call the http interface

string content =“test“; content = URL encoder . encode(content,“utf-8“); string URL =“http://localhost:8 180/atoz _ 20 14/http server? content =“+content+“& amp; mobiles = 1530 1895007“; URL httpTest please try {httptest = new URL (URL); BufferedReader intry { in = new buffered reader(new InputStreamReader(httptest . openstream())); String inputline = null String Resultmsg = null//Get the return information of xml string while((input line = in. readline ())! = null)if(result msg! = null){ result msg+= input line; } else { resultMsg = inputLine} in . close(); } catch(malformedurexception e){ e . printstacktrace(); }} catch(io exception e){//TODO automatically generated catch block e.printstacktrace (); }

Typing is not easy, hope to adopt, thank you.