警告:未找到映射

时间:2013-06-26 12:15:50

标签: spring web.xml

我正在尝试构建一个简单的sp [ring mvc,其中只有一个jsp登录页面。但是我无法在运行应用程序时查看它,因为我在控制台中收到以下警告:

警告:在名为“SpringBlogger”的DispatcherServlet中找不到带有URI [/SpringBlogger/WEB-INF/jsp/login.jsp]的HTTP请求的映射

web.xml:

查看plaincopy到clipboardprint? 注意:代码块中的文本内容是自动换行的

<?xml version="1.0" encoding="UTF-8"?>  
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">  
  <display-name>SpringBlogger</display-name>  
  <welcome-file-list>  
    <welcome-file>login.jsp</welcome-file>  
  </welcome-file-list>  

  <servlet>  
<servlet-name>SpringBlogger</servlet-name>  
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  
<load-on-startup>1</load-on-startup>  
</servlet>  
<servlet-mapping>  
<servlet-name>SpringBlogger</servlet-name>  
<url-pattern>*.jsp</url-pattern>  
</servlet-mapping>  
</web-app>  

SpringBlogger-servlet.xml

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

<mvc:annotation-driven/>  
<context:component-scan base-package="com.beans" />  

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">  
      <property name="prefix" value="/WEB-INF/jsp/" />  
      <property name="suffix" value=".jsp" />  
   </bean>  
</beans>  

HomeController.java: -

    package com.beans;  

import org.springframework.stereotype.Controller;  
import org.springframework.ui.ModelMap;  
import org.springframework.web.bind.annotation.RequestMapping;  

@Controller  
public class HomeController {  

    @RequestMapping("/login.jsp")  
    public String showHomePage(ModelMap map){  
        map.addAttribute("message", "Welcome to Spring Blogger");  
        return "login";  
    }  
}  

login.jsp: -

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"  
    pageEncoding="ISO-8859-1"%>  
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>  
<!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>  
<form action="LoginAction" method="post">  
<h1>${message}</h1>  
<table>  
<tr>  
<td>UserName: </td>  
<td><form:input path="UserName"/>  
</td>  
</tr>  

<tr>  
    <td>Password: </td>  
    <td><form:password path="Password"/></td>  
</tr>  

<tr>  
    <td colspan="2">  
        <input type="submit" value="submit">  
    </td>  
</tr>  
</table>  
</form>  
</body>  
</html>  

我知道在其他一些主题中已经提到过这类问题,但我没有解决我的问题,因为我已经包含但仍然遇到同样的错误。

请让我知道我错过了什么。

谢谢, 和Manish

1 个答案:

答案 0 :(得分:0)

请勿在{{1​​}}中使用*.jsp作为servlet映射。使用简单的斜杠web.xml