spring - Cannot find the controller class -


i'm starting learning spring mvc . simple helloworld project when i'm trying use controller methotds @requestmapping , there http status [404] – [not found] problem. i'm using sts.

http://localhost:8080/firsttest/ working i'm trying 'greeting' part , it's not working. (project name :firsttest)

( tried <url-pattern>/*</url-pattern> still not working)

thanks helps.

hellocontroller.java

@controller public class hellocontroller {      @requestmapping(value ="/greeting")     public string sayhello (model model) {          model.addattribute("greeting", "hello world");          return "hello";     }  }  

hello.jsp

<%@ page language="java" contenttype="text/html; charset=iso-8859-1"     pageencoding="iso-8859-1"%> <!doctype html public "-//w3c//dtd html 4.01 transitional//en" "http://www.w3.org/tr/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"> <title>insert title here</title> </head> <body> <h1>${greeting}</h1> </body> </html> 

servlet-config.xml

<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans"     xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"     xmlns:context="http://www.springframework.org/schema/context"     xmlns:mvc="http://www.springframework.org/schema/mvc"     xmlns:p="http://www.springframework.org/schema/p"     xsi:schemalocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">      <mvc:annotation-driven/>     <context:component-scan base-package="com.pluralsight.controller"/>      <!--      <bean class="org.springframework.web.servlet.view.internalresourceviewresolver">         <property name="prefix" value="/web-inf/jsp/"/>         <property name="suffix" value=".jsp"/>     </bean>      -->       <bean class="org.springframework.web.servlet.view.internalresourceviewresolver"       p:prefix="/web-inf/jsp/" p:suffix=".jsp" />  </beans> 

web.xml

<?xml version="1.0" encoding="utf-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"     xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"     xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">      <servlet>         <servlet-name>fittrackerservlet</servlet-name>         <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class>         <init-param>             <param-name>contextconfiglocation</param-name>             <param-value>/web-inf/config/servlet-config.xml</param-value>         </init-param>     </servlet>      <servlet-mapping>         <servlet-name>fittrackerservlet</servlet-name>         <url-pattern>*.html</url-pattern>      </servlet-mapping>      <display-name>archetype created web application</display-name> </web-app> 

pom.xml

<project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"   xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">   <modelversion>4.0.0</modelversion>   <groupid>com.pluralsight</groupid>   <artifactid>fitnesstracker</artifactid>   <packaging>war</packaging>   <version>0.0.1-snapshot</version>   <name>fitnesstracker maven webapp</name>   <url>http://maven.apache.org</url>   <dependencies>     <dependency>       <groupid>junit</groupid>       <artifactid>junit</artifactid>       <version>3.8.1</version>       <scope>test</scope>     </dependency>     <dependency>         <groupid>org.springframework</groupid>         <artifactid>spring-webmvc</artifactid>         <version>3.2.0.release</version>     </dependency>     <dependency>         <groupid>javax.servlet</groupid>         <artifactid>jstl</artifactid>         <version>1.2</version>         <scope>provided</scope>     </dependency>     <dependency>         <groupid>javax.servlet</groupid>         <artifactid>servlet-api</artifactid>         <version>2.5</version>         <scope>provided</scope>     </dependency>   </dependencies>   <build>     <finalname>fitnesstracker</finalname>   </build> </project> 

you need declare request method type in request mapping of controller.

    @requestmapping(value ="/greeting", method = requestmethod.get) 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -