gpt4 book ai didi

java - 简单的 Servlet 映射

转载 作者:行者123 更新时间:2023-12-01 15:50:33 24 4
gpt4 key购买 nike

我正在尝试将 Spring 实现到一个小应用程序上。我得到以下信息:

WARNING: No mapping found for HTTP request with URI [/audiClave/] in DispatcherServlet with name 'appServlet'

这是我的 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>audiClave</display-name>
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet- class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>

这是 servlet-context.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"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
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">

<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

<!-- Scans within the base package of the application for @Components to configure as beans -->
<!-- @Controller, @Service, @Configuration, etc. -->
<context:component-scan base-package="com.audiClave.Service" />

<!-- Enables the Spring MVC @Controller programming model -->
<mvc:annotation-driven />

</beans>

Controller 是:

package com.audiClave.Service;

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

/**
* Handles requests for the application home page.
*/
@Controller
public class HomeController {

@RequestMapping(value = "/")
public String home() {
System.out.println("HomeController: Passing through...");
return "WEB-INF/views/home.jsp";
}
}

http://localhost:8080/audiClave/返回:

HTTP Status 404
The requested resource () is not available.

我使用tomcat 7.0.12和spring 3.0.5在eclipse下运行。内容似乎已正确部署到 E:\development\java.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\audiClave

当我将映射更改为/* 时,它能够找到 Controller ,但是 home.jsp 不起作用,因为通配符也与其匹配

当我再次将/* 从映射中取出时已解决。谢谢

最佳答案

只需返回“home”(而不是jsp的整个路径)。 View 处理程序应配置为在该文件夹中查找具有该扩展名的 View 。

关于java - 简单的 Servlet 映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6138201/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com