Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7520777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:07:36+00:00 2026-05-30T02:07:36+00:00

i am trying to create and run a simple Spring 3.1 mvc web application

  • 0

i am trying to create and run a simple Spring 3.1 mvc web application where i have defined a controller that simply returns “hello” in the response body using the class below:

package com.jr.freedom.controllers;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class Hello {

    @RequestMapping(value = "/hello", method = RequestMethod.GET)
    @ResponseBody
    public String helloWorldInJson() {

        return "hello";
    }
}

i have tried this URL but i keeps returning a 404 error?

http://localhost:8080/FreedomSpring/hello

Here is my servlett:

<?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"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans      
        http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.1.xsd">

    <import resource="mvc-config.xml" />

    <bean
        class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />

    <!-- Resolves views selected for rendering by @Controllers to .jsp resources 
        in the /WEB-INF/views directory -->
    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/views/" />
        <property name="suffix" value=".jsp" />
    </bean>

    <bean
        class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />

    <context:component-scan base-package="com.jr.freedom.controllers"></context:component-scan>


</beans>

here is the web.xml file

<?xml version="1.0" encoding="UTF-8"?>

<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
         http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    <servlet>
        <servlet-name>FreedomSpring</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>FreedomSpring</servlet-name>
        <url-pattern>*.htm</url-pattern>
    </servlet-mapping>


    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>

        </param-value>
    </context-param>

    <context-param>
        <param-name>log4jConfigLocation</param-name>
        <param-value>/WEB-INF/log4j.xml</param-value>
    </context-param>

    <welcome-file-list>
        <welcome-file>
      index.jsp
    </welcome-file>
    </welcome-file-list>

    <listener>
        <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    </listener>

</web-app>

And finally my mvc-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
        http://www.springframework.org/schema/mvc 
        http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">

    <mvc:annotation-driven />

    <!-- the application context definition for the springapp DispatcherServlet -->


    <mvc:view-controller path="/" view-name="index.jsp" />


</beans>

I am using tomcat 7 on a windows 7 machine by the way. No errors are found from my logfile from tomcat:

13-Feb-2012 12:37:36 org.apache.catalina.core.ApplicationContext log
INFO: Destroying Spring FrameworkServlet 'FreedomSpring'
13-Feb-2012 12:37:36 org.apache.catalina.core.ApplicationContext log
INFO: Shutting down log4j
13-Feb-2012 12:37:36 org.apache.catalina.core.ApplicationContext log
INFO: Closing Spring root WebApplicationContext
13-Feb-2012 12:37:37 org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
13-Feb-2012 12:37:37 org.apache.catalina.core.ApplicationContext log
INFO: Set web app root system property: 'webapp.root' = [C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\FreedomSpring\]
13-Feb-2012 12:37:37 org.apache.catalina.core.ApplicationContext log
INFO: Initializing log4j from [C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\FreedomSpring\WEB-INF\log4j.xml]
13-Feb-2012 12:37:37 org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'FreedomSpring'


0:0:0:0:0:0:0:1 - - [13/Feb/2012:12:37:45 +0000] "GET /FreedomSpring HTTP/1.1" 302 -
0:0:0:0:0:0:0:1 - - [13/Feb/2012:12:37:45 +0000] "GET /FreedomSpring/ HTTP/1.1" 404 997
0:0:0:0:0:0:0:1 - - [13/Feb/2012:12:37:51 +0000] "GET /FreedomSpring/hello HTTP/1.1" 404 1012

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T02:07:39+00:00Added an answer on May 30, 2026 at 2:07 am

    Your DispatcherServlet is mapped to *.htm:

    <servlet-mapping>
        <servlet-name>FreedomSpring</servlet-name>
        <url-pattern>*.htm</url-pattern>
    </servlet-mapping>
    

    But you are accessing the controller through non-matching URL: http://localhost:8080/FreedomSpring/hello. You have three choices:

    1. Change you dispatcher servlet to:

      <servlet-mapping>
          <servlet-name>FreedomSpring</servlet-name>
          <url-pattern>/*</url-pattern>
      </servlet-mapping>
      

      but in this case all requests will be handled through the Spring MVC, including images and other static resources

    2. Use extension in controllers as well:

      <url-pattern>/*.htm</url-pattern>
      

      and map Hello controller to .htm so that you use: http://localhost:8080/FreedomSpring/hello.htm.

    3. Map controllers to a different subdirectory:

      <url-pattern>/mvc/*</url-pattern>
      

      to access them you will have to use: http://localhost:8080/FreedomSpring/mvc/hello without making any changes to the controller itself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a simple application that does a HTTP request/response on a
I'm trying to create a Textmate snippet, but have run into some difficulties. Basically,
I'm trying to create a simple prototype in JavaScript that removes a character from
Two questions. First question is I'm trying to create a simple form that when
I am trying to create a simple login system. When I run the login
I am trying to create a simple Applescript that is activated each time I
I'm trying to create a web user interface for a Java application. The user
I am trying to create a simple console based java application, which requires users
I'm new to WPF/C#, and I'm trying to create a simple sql query application
Trying to make a simple application in rails 3. If I create a team

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.