Java 源服务器没有找到目标资源的当前表示或不愿意透露一个存在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43931383/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
The origin server did not find a current representation for the target resource or is not willing to disclose that one exists
提问by sagar limbu
web.xml
网页.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
优惠-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>
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?
这里有什么问题?我无法访问 home.jsp。我实际上正在观看 spring 3.0 中的教程,并且我已经完成了视频中显示的内容。有人可以在这里指出我的错误吗?
采纳答案by sagar limbu
the problem is in url pattern of servlet-mapping.
问题出在 servlet 映射的 url 模式中。
<url-pattern>/DispatcherServlet</url-pattern>
let's say our controller is
假设我们的控制器是
@Controller
public class HomeController {
@RequestMapping("/home")
public String home(){
return "home";
}
}
when we hit some URL on our browser. the dispatcher servlet will try to map this url.
当我们在浏览器上点击某个 URL 时。调度程序 servlet 将尝试映射此 url。
the url pattern of our serlvet currently is /Dispatcher
which means resources are served from {contextpath}/Dispatcher
我们的 serlvet 的 url 模式目前是/Dispatcher
这意味着资源是从{contextpath}/Dispatcher
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
但是当我们请求时,我们http://localhost:8080/home
实际上是在请求/
不可用的资源。所以要么我们需要说调度程序servlet/
通过做
<url-pattern>/</url-pattern>
our make it serve from /Dispatcher by doing /Dispatcher/*
我们让它从 /Dispatcher 提供服务 /Dispatcher/*
E.g
例如
<?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>
and request it with http://localhost:8080/Dispatcher/home
or put just /
to request like
并请求它http://localhost:8080/Dispatcher/home
或只是/
请求像
http://localhost:8080/home
回答by Ashish Patel
org.glassfish.jersey.servlet.ServletContainer.class
org.glassfish.jersey.servlet.ServletContainer.class
here remove .class
这里删除 .class
org.glassfish.jersey.servlet.ServletContainer now you wont get
org.glassfish.jersey.servlet.ServletContainer 现在你不会得到
回答by Shahid Hussain Abbasi
I added yellow highlighted package and now my view page is accessible. in eclipse when we deploy our war it only deploy those stuff mention in the deployment assessment.
我添加了黄色突出显示的包,现在我的视图页面可以访问。在 Eclipse 中,当我们部署战争时,它只部署部署评估中提到的那些东西。
We set Deployment Assessment from right click on project --> Properties --> Apply and Close....
我们通过右键单击项目 --> 属性 --> 应用并关闭...来设置部署评估。
回答by KernelMode
回答by Michal Zajac
回答by Smitha
There is one more way to solve this problem. 1)Go to Project Explorer. Go to the target folder of your project, right-click and delete the target folder. 2)Right-click on your project, select run as Maven Build. 3)After you get Build Success on the console; right click on the project folder and select refresh. After performing the above steps, try to run your project.Your problem should be solved now.
还有一种方法可以解决这个问题。1) 转到项目资源管理器。转到项目的目标文件夹,右键单击并删除目标文件夹。2) 右键单击您的项目,选择 run as Maven Build。3) 在控制台获得 Build Success 后;右键单击项目文件夹并选择刷新。执行完上述步骤后,尝试运行您的项目。您的问题现在应该解决了。
回答by Gowtham Gopalakrishnan
I was running the project through Intellij and this got this error after I stopped the running server and restarted it. Killing all the java processes and restarting the app helped.
我正在通过 Intellij 运行该项目,并且在我停止正在运行的服务器并重新启动它后出现此错误。杀死所有 Java 进程并重新启动应用程序有帮助。
回答by neeraj
In case of springboot app on tomcat, I needed to create an additional class as below and this worked:
在 tomcat 上的 springboot 应用程序的情况下,我需要创建一个额外的类,如下所示,这有效:
@SpringBootApplication
public class SpringBootTomcatApplication extends SpringBootServletInitializer {
}
回答by George Stone
I had the same problem and spent about 6 hours to solve it. I didn't find that answer for exactly my situation so maybe it could be useful for somebody.
我遇到了同样的问题,花了大约 6 个小时来解决它。我没有找到完全适合我的情况的答案,所以也许它对某人有用。
When I created project, I pointed GroupId in pom.xml as "myproject.myapp" but I didn't create first "prime" package with that name in the project, where would be other packages inside of this main package (like /src/main/app etc). When I created prime package "myproject.myapp" and moved other packages inside of it, the problem was solved.
当我创建项目时,我将 pom.xml 中的 GroupId 指向为“myproject.myapp”,但我没有在项目中创建第一个具有该名称的“prime”包,这个主包中的其他包(如 /src /main/app 等)。当我创建主要包“myproject.myapp”并将其他包移动到其中时,问题就解决了。
回答by Oly
Was following one of training with Spring webmvc 4.2.3, while I'm using Spring webmvc 5.2.3 they suggested to create a form
正在接受 Spring webmvc 4.2.3 的培训之一,而我使用的是 Spring webmvc 5.2.3,他们建议创建一个表单
<form:form modelAttribute="aNewAccount" method="get" action="/accountCreated">
that was causing the "disclose" error.
这导致了“披露”错误。
Altered as below to make it work. Looks like method above was the culprit.
如下更改以使其工作。看起来上面的方法是罪魁祸首。
<form:form modelAttribute="aNewAccount" action="accountCreated.html">
in fact, exploring further, method="post" in form annotation would work if properly declared:
事实上,进一步探索,如果正确声明,表单注释中的 method="post" 将起作用:
@RequestMapping(value="/accountCreated", method=RequestMethod.POST)