原始服务器没有找到目标资源的当前表示,或者不愿意透露存在该目标资源 [英] The origin server did not find a current representation for the target resource or is not willing to disclose that one exists
问题描述
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>springsecuritydemo</display-name>
<!-- <welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list> -->
<servlet>
<description></description>
<display-name>offers</display-name>
<servlet-name>offers</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>offers</servlet-name>
<url-pattern>/DispatcherServlet</url-pattern>
</servlet-mapping>
</web-app>
offers-sevlet.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/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<context:component-scan base-package="com.spring.security.web"></context:component-scan>
<mvc:annotation-driven></mvc:annotation-driven>
<bean name="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsps/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
</beans>
这里有什么问题?我无法访问home.jsp。
我实际上是在春季3.0观看教程,我已经完成了视频中的显示。谁能在这里指出我的错误?
what is wrong here? i cannot access home.jsp. i am actually watching a tutorial in spring 3.0 and i have done exactly shown in video. can anyone point my mistake here?
推荐答案
问题在于servlet-mapping的url模式。
the problem is in url pattern of servlet-mapping.
<url-pattern>/DispatcherServlet</url-pattern>
假设我们的控制器是
@Controller
public class HomeController {
@RequestMapping("/home")
public String home(){
return "home";
}
}
当我们在浏览器上点击某个网址时。调度程序servlet将尝试映射此URL。
when we hit some URL on our browser. the dispatcher servlet will try to map this url.
我们的serlvet的url模式目前是 / Dispatcher
,这意味着资源来自 {contextpath} / Dispatcher
the url pattern of our serlvet currently is /Dispatcher
which means resources are served from {contextpath}/Dispatcher
但是当我们请求 http:// localhost:8080 / home $ c时$ c>我们实际上要求
/
中的资源不可用。
所以要么我们需要说调度员servlet从 /
服务
but when we request http://localhost:8080/home
we are actually asking resources from /
which is not available.
so either we need to say dispatcher servlet to serve from /
by doing
<url-pattern>/</url-pattern>
我们通过 / Dispatcher / * 来自/ Dispatcher服务code>
例如
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID"
version="3.1">
<display-name>springsecuritydemo</display-name>
<servlet>
<description></description>
<display-name>offers</display-name>
<servlet-name>offers</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>offers</servlet-name>
<url-pattern>/Dispatcher/*</url-pattern>
</servlet-mapping>
</web-app>
并请求 http:// localhost:8080 / Dispatcher / home
或只需 /
就可以请求
http://localhost:8080/home
这篇关于原始服务器没有找到目标资源的当前表示,或者不愿意透露存在该目标资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!