Note that there are some explanatory texts on larger screens.

plurals
  1. PO@RequestMapping not working in spring mvc
    text
    copied!<p>I am relatively new to spring mvc. i am not able to get the page navigation to work. i looked through the documentation and other forums for help, but I am not able to figure out where I am going wrong. can someone please help..</p> <p>I get 404 when I try to access appointments.jsp</p> <p>Controller</p> <pre><code>package com.mycompany.myapp; @Controller public class HomeController { private static final Logger logger = LoggerFactory.getLogger(HomeController.class); @RequestMapping(value = "/", method = RequestMethod.GET) public String home(Locale locale, Model model) { logger.info("Welcome home! The client locale is {}.", locale); return "home"; } @RequestMapping(value = "/appointments", method = RequestMethod.GET) public String appointments(Locale locale, Model model){ return "appointments"; } } </code></pre> <p>web.xml</p> <pre><code>&lt;context-param&gt; &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt; &lt;param-value&gt;/WEB-INF/spring/root-context.xml&lt;/param-value&gt; &lt;/context-param&gt; &lt;!-- Creates the Spring Container shared by all Servlets and Filters --&gt; &lt;listener&gt; &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt; &lt;/listener&gt; &lt;!-- Processes application requests --&gt; &lt;servlet&gt; &lt;servlet-name&gt;appServlet&lt;/servlet-name&gt; &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt; &lt;init-param&gt; &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt; &lt;param-value&gt;/WEB-INF/spring/appServlet/servlet-context.xml&lt;/param-value&gt; &lt;/init-param&gt; &lt;load-on-startup&gt;1&lt;/load-on-startup&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;appServlet&lt;/servlet-name&gt; &lt;url-pattern&gt;/&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; &lt;/web-app&gt; </code></pre> <p>servlet-context.xml</p> <pre><code>&lt;!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure --&gt; &lt;!-- Enables the Spring MVC @Controller programming model --&gt; &lt;annotation-driven /&gt; &lt;!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory --&gt; &lt;resources mapping="/resources/**" location="/resources/" /&gt; &lt;!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory --&gt; &lt;beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt; &lt;beans:property name="prefix" value="/WEB-INF/views/" /&gt; &lt;beans:property name="suffix" value=".jsp" /&gt; &lt;/beans:bean&gt; &lt;context:component-scan base-package="com.mycompany.myapp" /&gt; &lt;/beans:beans&gt; </code></pre> <p>home.jsp</p> <pre><code>&lt;%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%&gt; &lt;%@ page session="false"%&gt; &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt; &lt;!-- Bootstrap --&gt; &lt;link href="//netdna.bootstrapcdn.com/bootswatch/2.3.2/amelia/bootstrap.min.css" rel="stylesheet"&gt; &lt;/head&gt; &lt;body&gt; &lt;script src="http://code.jquery.com/jquery.js"&gt;&lt;/script&gt; &lt;script src="//netdna.bootstrapcdn.com/twitter- bootstrap/2.3.2/js/bootstrap.min.js"&gt;&lt;/script&gt; &lt;div class="navbar"&gt; &lt;div class="navbar-inner"&gt; &lt;div class="container"&gt; &lt;a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse"&gt; &lt;span class="icon-bar"&gt;&lt;/span&gt; &lt;span class="icon-bar"&gt;&lt;/span&gt; &lt;span class="icon-bar"&gt;&lt;/span&gt; &lt;/a&gt; &lt;a class="brand" href="#"&gt;Doctor Assist&lt;/a&gt; &lt;ul class="nav"&gt; &lt;li class="active"&gt;&lt;a href="#"&gt;Home&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="/appointments.jsp"&gt;Appointments&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Patient Data&lt;/a&gt;&lt;/li&gt; &lt;li class="dropdown"&gt;&lt;a href="#" class="dropdown-toggle" data-toggle="dropdown"&gt; Account &lt;b class="caret"&gt;&lt;/b&gt; &lt;/a&gt; &lt;ul class="dropdown-menu"&gt; &lt;li&gt;&lt;a href="#"&gt;Personal&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Link&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;h1&gt;work in progress&lt;/h1&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>appointments.jsp</p> <pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt; &lt;/head&gt; &lt;body&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload