0

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

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

网页.xml:

查看plaincopy到剪贴板打印?注意:代码块中的文本内容会自动换行

<?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";  
    }  
}  

登录.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>  

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

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

谢谢,马尼什

4

2 回答 2

0

不要*.jspweb.xml. 使用简单的斜线/

于 2013-06-26T12:31:54.590 回答
0

web.xml

<?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>index.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>/</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>

家庭控制器.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(value="/login",method=RequestMethod.POST")  
    public String showHomePage(ModelMap map){  
        map.addAttribute("message", "Welcome to Spring Blogger");  
        return "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="/login" 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>
于 2015-08-27T06:53:36.580 回答