The development environment is spring Tool Suite;
First, configure the Sts.ini, the configuration file is as follows:
-startup
Plugins/org.eclipse.equinox.launcher_1.3.200.v20160318-1642.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.400.v20160518-1444
-product
Org.springsource.sts.ide
--launcher.defaultaction
OpenFile
-vmargs
-dosgi.requiredjavaversion=1.8
-xms40m
-xverify:none
-dorg.eclipse.swt.browser.ieversion=10001
-xmx1200m
-dfile.encoding=utf-8 (last line Add code, set encoding format to UTF-8)
Second, add the Tomcat server to the STS (note to change the JDK to its own installed JDK);
Third, new dynamic Web Project;
Iv. Create a new class, inherit the HttpServlet class, and overwrite the Doget () method of the parent class;
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;//inherit HttpServlet class; public class Testservlet extends HttpServlet {private static Final long Serialversionuid = -514345712229720561l;//overrides Doget () method; @Overrideprotected void Doget (HttpServletRequest req , HttpServletResponse resp) throws Servletexception, IOException {//through the setContentType () method, set the encoding format to UTF-8, otherwise Chinese garbled ; Resp.setcontenttype ("Text/html;charset=utf-8");//Returns a byte of output stream PrintWriter () via getwriter (); PrintWriter pw = Resp.getwriter ();p w.println ("V. Configuration of Web. xml;
<?xml version= "1.0" encoding= "UTF-8"? ><web-app xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns= "Http://xmlns.jcp.org/xml/ns/javaee" xsi:schemalocation= "Http://xmlns.jcp.org/xml/ns/javaee/http Xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd "id=" webapp_id "version=" 3.1 "> <servlet> < servlet-name>TS</servlet-name> <servlet-class>testservlet</ servlet-class> </servlet> <servlet-mapping> <servlet-name>TS </servlet-name> <url-pattern>/Hello</url-pattern> </servlet-mapping ></web-app>
Where the Testservlet in,<servlet-class>testservlet</servlet-class> is the class name, two <servlet-name>ts</ Servlet-name> TS in the same can be;<url-pattern>/hello</url-pattern> in the/hello for the browser access to the domain name;
Six, add Testservlet project, open Tomcat server, Enter the Http://localhost:8080/servlet01/hello in the browser, and you can see the 100 "Min Nong" displayed on the webpage;
#注: If the browser input address when the class is not Found Exception, the page prompts 500 error, you need to delete tomcat after the re-add it;
Publish a simple website with 100 "min Nong" (Practice STS Usage, Web. XML configuration, Tomcat release process)