In the SSH framework, how to get the URL and parameter list of the POST request

Source: Internet
Author: User

When doing the API notification interface of the project, it is found that the asynchronous notification information sent to the other server is not available in the SSH framework.
The last reason for troubleshooting may be that struts2 to the HttpServletRequest two times, then how to get the POST request data, a lot of methods, the following only one way.

A GET request in a servlet can get the full request path and request all the parameter lists through the HttpServletRequest Getrequesturl method and the GetQueryString ().

Post needs to be traversed by the Getparametermap () method, either get or post can be getrequesturl+getparametermap () to obtain the requested full path.

 Packagecom.xxxImportjava.io.IOException;ImportJava.io.PrintWriter;ImportJava.util.Map;Importjavax.servlet.ServletException;ImportJavax.servlet.http.HttpServlet;Importjavax.servlet.http.HttpServletRequest;ImportJavax.servlet.http.HttpServletResponse; Public classGetparamsextendsHttpServlet {Private Static Final LongSerialversionuid = 1L;  PublicGetparams () {Super(); }    protected voiddoget (httpservletrequest request, httpservletresponse response)throwsservletexception, IOException {printwriter writer=Response.getwriter (); Writer.println ("GET" + request.getrequesturl () + "" +request.getquerystring ()); Map<string, string[]> params =Request.getparametermap (); String queryString= "";  for(String key:params.keySet ()) {string[] values=Params.get (key);  for(inti = 0; i < values.length; i++) {String value=Values[i]; QueryString+ = key + "=" + Value + "&"; }        }        //remove the last spacequeryString = querystring.substring (0, Querystring.length ()-1); Writer.println ("GET" + request.getrequesturl () + "" +queryString); }    protected voidDoPost (httpservletrequest request, httpservletresponse response)throwsservletexception, IOException {printwriter writer=Response.getwriter (); Map<string, string[]> params =Request.getparametermap (); String queryString= "";  for(String key:params.keySet ()) {string[] values=Params.get (key);  for(inti = 0; i < values.length; i++) {String value=Values[i]; QueryString+ = key + "=" + Value + "&"; }        }        //remove the last spacequeryString = querystring.substring (0, Querystring.length ()-1); Writer.println ("POST" + request.getrequesturl () + "" +queryString); }}                    

According to the above code, a slight change, the implementation of the following:

/*** Get post data, do not support array form data, general use scenario is the other side use post to pass data over * TODO to perfect *@authorPhpdragon * @date 2014-12-24 pm 3:45:22 *@return* @description: *@returnmap<string,string> *@throws     */@SuppressWarnings ("Unchecked")    Private StaticMap<string, string>Getpostdata () {Map<string, string> param =NewHashmap<string, string>(); HttpServletRequest Request=servletactioncontext.getrequest (); Map<string, string[]> params =Request.getparametermap ();  for(String key:params.keySet ()) {string[] values=Params.get (key);  for(inti = 0; i < values.length; i++) {param.put (key, Values[i]); }        }        returnparam; }

Although it is not enough, the API interface scenario for the project in hand has already met the requirements.

In the SSH framework, how to get the URL and parameter list of the POST request

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.