Java spring-jstl-Error 404-请求的资源不可用
当我想访问我的网站时,我有以下错误:Java spring-jstl-Error 404-请求的资源不可用,java,spring,spring-mvc,servlets,Java,Spring,Spring Mvc,Servlets,当我想访问我的网站时,我有以下错误: The requested resource is not available. 我注意到问题出现在行上的mvc-dispatcher-servlet.xml文件中,但我不知道为什么 你有什么解决办法吗 我的项目结构: - src - main - java - com - myblog - controller -//all java files as controll
The requested resource is not available.
我注意到问题出现在行
上的mvc-dispatcher-servlet.xml文件中,但我不知道为什么
你有什么解决办法吗
我的项目结构:
- src
- main
- java
- com
- myblog
- controller
-//all java files as controller
- resources
- normalMode
- css
- header.css
- webapp
- /WEB-INF
- /pages
- mvc-dispatcher.xml
- web.xml
mvc-dispatcher-servlet.xml
<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/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="com.myblog.controller" />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property value="org.springframework.web.servlet.view.JstlView"
name="viewClass" />
<property name="prefix">
<value>/WEB-INF/pages/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<mvc:resources mapping="/resources/**" location="../../resources/normalMode/"/>
</beans>
您需要添加
<mvc:annotation-driven/>
到您的mvc dispatcher servlet.xml
。通过此配置(以及组件扫描),Spring将扫描并注册用@RequestMapping
注释的@Controller
方法
在您当前的配置中,没有注册这样的处理程序,因此没有什么可以处理您对
/
的请求。首先,如果类路径上没有.xml文件,则需要加载它们
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:spring/application-config.xml,
/WEB-INF/conf/mvc-config.xml
</param-value>
</context-param>
上下文配置位置
类路径:spring/application-config.xml,
/WEB-INF/conf/mvc-config.xml
现在,您需要执行以下操作以使用注释启用SpringMVC
<context:component-scan base-package="com.ekiras" />
<mvc:annotation-driven />
<tx:annotation-driven />
您需要启用注释和组件扫描来扫描项目中的所有注释
对于哪个请求,您会收到该错误?什么URL?是
lbagno
您的上下文路径吗?我们也来看看你的web.xml。原型创建了Web应用程序mvc dispatcher org.springframework.Web.servlet.DispatcherServlet 1 mvc dispatcher/完成了。你可以看到我有个问题。“”和“”@user2274060
之间有什么区别?设置DispatcherServlet
所需的bean。它在您的上下文中查找具有@Controller
注释的任何bean,并为@RequestMapping
方法生成处理程序方法
扫描指定的包,查找用@组件注释的类(或其子类型@Repository
、@Service
、@Controller
等),并为它们创建bean。因此,您需要组件扫描
来生成bean,并且需要注释驱动
来处理它们。@user2274060我知道您以前问过一些问题,但没有接受任何答案。考虑支持你的投票/接受答案。
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:spring/application-config.xml,
/WEB-INF/conf/mvc-config.xml
</param-value>
</context-param>
<context:component-scan base-package="com.ekiras" />
<mvc:annotation-driven />
<tx:annotation-driven />