java - Spring MVC with Tomcat won't open Hello World html page -


i'm trying open simple html page writes hello world, on localhost:8080/hello inside spring mvc app. use spring boot comes own tomcat.

web.xml

<?xml version="1.0" encoding="utf-8"?> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"          xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"          xsi:schemalocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"          version="3.1">     <display-name>angular rest spring</display-name>      <servlet>         <servlet-name>angular</servlet-name>         <servlet-class>             org.springframework.web.servlet.dispatcherservlet         </servlet-class>     </servlet>      <servlet-mapping>         <servlet-name>angular</servlet-name>         <url-pattern>*</url-pattern>     </servlet-mapping> </web-app> 

i tried putting page inside:

app/src/main/resources app/src/main/resources/templates web web/web-inf 

it can't find it. says:

whitelabel error page  application has no explicit mapping /error, seeing fallback.  wed sep 07 15:52:20 eest 2016 there unexpected error (type=not found, status=404). no message available 

any ideas?

if using spring boot there no need writing web.xml. spring automatically maps @controller annotated classes , reads @requestmapping annotations those.

write application class :

package com.sample.web;  import org.springframework.boot.springapplication; import org.springframework.boot.autoconfigure.springbootapplication;  @springbootapplication(scanbasepackages = "com.sample.web") public class application {      public static void main(string[] args) {         springapplication.run(application.class, args);     }  } 

write controller class like this:

package com.sample.web;  import org.springframework.stereotype.controller; import org.springframework.ui.model; import org.springframework.web.bind.annotation.requestmapping; import org.springframework.web.bind.annotation.requestparam;  @controller public class hellocontroller {      @requestmapping("/hello")     public string hello(model model) {         return "hello";     }  } 

and write template html file in src/main/resources/templates :

<!doctype html> <html xmlns:th="http://www.thymeleaf.org"> <head>     <title>getting started: serving web content</title>     <meta http-equiv="content-type" content="text/html; charset=utf-8" /> </head> <body> hello </body> </html> 

i use intellij in can run application class make hello page available on http://localhost:8080/hello


Comments

Popular posts from this blog

serialization - Convert Any type in scala to Array[Byte] and back -

matplotlib support failed in PyCharm on OSX -

python - Matplotlib: TypeError: 'AxesSubplot' object is not callable -