Java Write get Access data (springmvc+spring ... )

Source: Internet
Author: User

Write API interface, summed up, but this splicing URL of the way, do not know whether it can be used as an API interface to obtain data

First add such a configuration to Web. xml

<!--test-
<servlet>
<servlet-name>BrandServlet</servlet-name>
<servlet-class>com.test.servlet.testa</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>BrandServlet</servlet-name>
<url-pattern>/jiekou.a</url-pattern>
</servlet-mapping>
<!--Test Junction--

Then fill in the code with the method

1  PackageCom.test.servlet;2 Importjava.io.IOException;3 ImportJava.io.PrintWriter;4 5 Importjavax.servlet.http.*;6 7  Public classTestaextendsHttpServlet {8 @Override9      Public voiddoget (httpservletrequest rq,httpservletresponse res) {Ten          One         Try { AString s= Rq.getparameter ("a"). toString (); -Res.setcharacterencoding ("UTF-8"); -PrintWriter pw=Res.getwriter (); the           -Pw.write ("Canshu:" +s);//go to JSON - pw.close (); -}Catch(IOException e) { +             //TODO auto-generated Catch block -E.printstacktrace ();// +         } A     } at}
View Code

Visit the URL http://localhost:8080/(your own project name)/jiekou.a?a=zhong several access to

Canshu:zhong

Java Write get Access data (springmvc+spring ... )

Related Article

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.