Javaweb from getting started to giving up (2)-giving local access to the interface __java

Source: Internet
Author: User

On an article, painstakingly configured the development environment, finally can happily open (Zhuang) hair (BI)


First to some wild way, do the mobile side of the development of the server to return the data has not been understood, now let's get a This bar.

According to the guidelines, you need a class to inherit Httpservelt, and then rewrite Dopost or doget to be happy to return to processing.

The rest of the thing is:

1. Write Return Data logic

	Resp.setheader ("Content-type", "Text/html;charset=utf-8");  
	Req.setcharacterencoding ("Utf-8");
	Resp.setcharacterencoding ("Utf-8");
	PrintWriter out = Resp.getwriter ();
	Out.write ("Information of the request");
	Out.close ();
	out = null;


2. Configure to allow access to the outside world

First configure this servelt: in Web.xml file modification

<!--give this servelt first name-->
  <servlet>
  <servlet-name>TestServelt</servlet-name>
  <servlet-class>com.test.c_171030.TestServelt</servlet-class>
  </servlet>
  <!-- And then, according to the alias, configure him to go out.-->
  <servlet-mapping>
    <servlet-name>TestServelt</servlet-name>
    <url-pattern>/myServelt</url-pattern>
  </servlet-mapping>

Originally Tomcat's Access interface was 8080, replacing 8080 with HTTP's default 80 port, modifying the Server.xml file

  <!--Modify the default request Port-->
    <connector connectiontimeout= "20000" port= "protocol=" http/1.1 "redirectport=" 8443 "
    uriencoding=" UTF-8 "
    />



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.