Java Spring MVC project Build (iii)--"Hello World"

Source: Internet
Author: User

In spring's configuration file, we define a bean, and spring will generate the object at startup.

<= "HelloWorld"  class= "Com.game.controller.Helloworld " >  </beans>

Now let's take a look at this file.

First, on the Java Resource-src, right-click New->package Build Com.game.controller build a package, then right-click on the package on the New->class, The class name is HelloWorld, and then click Finish. The project structure follows:

Let me look at the contents of Helloworld.java:

 PackageCom.game.controller;Importjava.io.IOException;Importjavax.servlet.http.HttpServletRequest;ImportJavax.servlet.http.HttpServletResponse;ImportOrg.springframework.stereotype.Controller;Importorg.springframework.web.bind.annotation.RequestMapping; @Controller Public classHelloworld {@RequestMapping ("/helloworld")//here control the access path in the browser specifically:/springdemo/helloworld     Public voidHelloWorld (HttpServletRequest request, httpservletresponse response)throwsIOException {//Output StringResponse.getwriter (). Append ("Hello World"); }}

The HelloWorld content is simple through the Servlet output object output string "Hello World". Below we start the server and run it in the browser to see the results.

Configure the server first (Tomcat must be installed beforehand), and in Helloworld.java right-click on Run server and select our configured tomcat 8.5

Start the server:

After successful startup, open browser input http://localhost:8080/SpringDemo/helloworld:

Java Spring MVC project Build (iii)--"Hello World"

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.