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

  • SEARCH
  • Home
  • 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 6100193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:21:29+00:00 2026-05-23T13:21:29+00:00

I’m new bee to spring. Just started my sample application in sprinv mvc. But,

  • 0

I’m new bee to spring. Just started my sample application in sprinv mvc. But, I can’t able to view the page since it is showing “The requested resource () is not available.” Cannot figure out where is the problem. I’m pasting the code below.

web.xml:

<?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>my</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>my</servlet-name>
    <url-pattern>*.html</url-pattern>
</servlet-mapping>   
<welcome-file-list>
<welcome-file>
index.jsp
</welcome-file>
</welcome-file-list>    
</web-app>

**

my-servlet.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

<bean  class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
  <property name="prefix" value="/jsp/"/>
  <property name="suffix" value=".jsp"/>
</bean>    
<bean name="/index.html" class="mypackage.web.myController"/>

</beans>

**

MyController.java

**

package mypackage.web;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

public class myController implements Controller{
public ModelAndView handleRequest(HttpServletRequest req,HttpServletResponse resp)    throws ServletException,IOException{
String msg="Hello!!! I'm coming from Controller. You Catched me ";
ModelAndView mv = new ModelAndView("index");
mv.addObject("message",msg);
return mv;
}
}

index.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="i" uri="http://java.sun.com/jsp/jstl/core" %>
<!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=UTF-8">
    <title>My First Application in Spring</title>
</head>

<body>
    <p>Check Below</p>
    <p>
        <em>${message}</em>
    </p>
</body>
</html>
  • 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-23T13:21:29+00:00Added an answer on May 23, 2026 at 1:21 pm

    It’s almost configured correctly, so well done so far 🙂 There are a couple of minor problems here that are causing the problems you see. Firstly, the bean is currently defined with a lowercase m:

    <bean name="/index.html" class="mypackage.web.myController"/>
    

    Although this is allowed, it is not conventional, so Spring will not be able to find the correct bean without some additional configuration.

    Also, it was not clear from the question which URL you are using, but it should be something of the form http://localhost:8080/<project>/myIndex.html

    There is a good summary of the convention here.

    So we have 2 options… either rename the class to MyController and save as MyController.java or modify the ControllerClassNameHandlerMapping bean to be case sensitive like so:

    <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping">
        <property name="caseSensitive" value="true" />
    </bean>
    

    Furthermore, it is not the cause of the problem but if you use the ControllerClassNameHandlerMapping you can omit bean name, so you can just use:

    <bean class="mypackage.web.MyController"/>
    

    I guess the most annoying part is that the web application deploys without error. However if you examine the log, there is a marked difference:

    Deployment of incorrectly configured webapp:

    04-Jul-2011 09:13:58 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
    INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@5f0e7d: defining beans []; root of factory hierarchy
    04-Jul-2011 09:13:58 org.springframework.web.servlet.FrameworkServlet initServletBean
    INFO: FrameworkServlet 'my': initialization completed in 157 ms
    

    Deployment of correctly configured webapp:

    04-Jul-2011 09:15:33 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
    INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@de537: defining beans [org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping#0,viewResolver,mypackage.web.MyController#0]; root of factory hierarchy
    04-Jul-2011 09:15:49 org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
    INFO: Mapped URL path [/my*] onto handler 'mypackage.web.MyController#0'
    04-Jul-2011 09:15:49 org.springframework.web.servlet.FrameworkServlet initServletBean
    INFO: FrameworkServlet 'my': initialization completed in 296 ms
    

    Secondly, once the mapping is fixed, you may discover that the JSP is not found. In the sample I created, I added the views under /WEB-INF/jsp so I needed to update the prefix property in my-servlet.xml to <property name="prefix" value="/WEB-INF/jsp/"/>. However depending on the location of your views, you may not need to do this.

    Personally I find the annotation based approach for MVC in Spring much easier to configure and follow, so I will recommend that you read REST in Spring 3: @MVC as you might find that easier to implement.

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

Sidebar

Related Questions

No related questions found

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.