【问题标题】:The origin server did not find a current representation for the target resource or is not willing to disclose that one exists源服务器没有找到目标资源的当前表示或不愿意透露存在的表示
【发布时间】:2017-05-12 07:04:44
【问题描述】:

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 的教程,并且我已经在视频中完全展示了。谁能在这里指出我的错误?

【问题讨论】:

  • 您找到解决方案了吗?

标签: java spring


【解决方案1】:

问题在于 servlet-mapping 的 url 模式。

 <url-pattern>/DispatcherServlet</url-pattern>

假设我们的控制器是

@Controller
public class HomeController {
    @RequestMapping("/home")
    public String home(){
        return "home";
    }
}

当我们在浏览器上点击某个 URL 时。调度程序 servlet 将尝试映射此 url。

我们的 serlvet 的 url 模式目前是 /Dispatcher,这意味着资源来自 {contextpath}/Dispatcher

但是当我们请求http://localhost:8080/home 时,我们实际上是在向/ 请求资源,这是不可用的。 所以要么我们需要说调度程序 servlet 从/ 提供服务

<url-pattern>/</url-pattern>

我们通过 /Dispatcher/* 使其从 /Dispatcher 提供服务

例如

<?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

【讨论】:

  • 很好的说明,它确实帮助了我
【解决方案2】:

我在 Tomcat 运行\调试配置中缺少应用程序上下文:

添加它,解决了问题,我得到了正确的响应,而不是“源服务器未找到...”

【讨论】:

    【解决方案3】:

    我添加了黄色突出显示的包,现在可以访问我的查看页面。在 Eclipse 中,当我们部署我们的战争时,它只部署部署评估中提到的那些东西。

    我们通过右键单击项目来设置部署评估 --> 属性 --> 应用并关闭......

    【讨论】:

    • 我遇到了与此非常相似的问题,但我没有添加“/src/main/webapps”,而是添加了“Maven Dependencies”,然后它就开始工作了。
    【解决方案4】:

    我在 InteliJ 中遇到了这个问题。我去了:Edit -> Configuration -> Deployment -> EditArtifact

    然后那里出现黄色问题,我只需单击两次修复即可。我希望这会对某人有所帮助。

    【讨论】:

    • 这与之前的答案有什么不同,特别是@KernelMode 的答案。
    【解决方案5】:

    还有另一种方法可以解决这个问题。 1)转到项目资源管理器。转到项目的目标文件夹,右键单击并删除目标文件夹。 2) 右键单击​​您的项目,选择作为 Maven Build 运行。 3)在控制台上构建成功后;右键单击项目文件夹并选择刷新。 执行上述步骤后,尝试运行您的项目。您的问题现在应该解决了。

    【讨论】:

      【解决方案6】:

      我通过 Intellij 运行项目,在我停止运行的服务器并重新启动它后出现此错误。杀死所有 java 进程并重新启动应用程序有所帮​​助。

      【讨论】:

        【解决方案7】:

        org.glassfish.jersey.servlet.ServletContainer.class

        这里删除.class

        org.glassfish.jersey.servlet.ServletContainer 现在你不会得到 ​​p>

        【讨论】:

        • 你必须证明为什么这会解决他的问题。
        【解决方案8】:

        如果是tomcat上的springboot应用程序,我需要创建一个额外的类,如下所示:

        @SpringBootApplication 
        public class SpringBootTomcatApplication extends SpringBootServletInitializer {
        }
        

        【讨论】:

          【解决方案9】:

          我遇到了同样的问题,花了大约 6 个小时来解决它。我没有找到完全适合我的情况的答案,所以它可能对某人有用。

          当我创建项目时,我将 pom.xml 中的 GroupId 指定为“myproject.myapp”,但我没有在项目中创建第一个具有该名称的“prime”包,这个主包中的其他包在哪里(像 /src/main/app 等)。当我创建主包“myproject.myapp”并在其中移动其他包时,问题就解决了。

          【讨论】:

            【解决方案10】:

            正在使用 Spring webmvc 4.2.3 进行培训,而我正在使用 Spring webmvc 5.2.3,他们建议创建一个表单

            <form:form modelAttribute="aNewAccount" method="get" action="/accountCreated">
            

            这导致了“披露”错误。

            如下更改以使其工作。看起来上面的方法是罪魁祸首。

            <form:form modelAttribute="aNewAccount" action="accountCreated.html">
            

            事实上,进一步探索,如果正确声明,表单注释中的 method="post" 将起作用:

            @RequestMapping(value="/accountCreated", method=RequestMethod.POST)
            

            【讨论】:

              【解决方案11】:

              网站运行良好,然后突然开始显示同样的错误 404 消息(源服务器未找到目标资源的当前表示或不愿意透露存在的表示),可能是因为切换回服务器并从 Tomcat 9 转发到 8 和 7

              就我而言,我只需要更新导致此错误的项目,然后重新启动特定的 tomcat 版本。您可能还需要在“Maven 更新项目”之后进行 Maven Clean 和 Maven Install

              【讨论】:

                【解决方案12】:

                如果您有错误来源“服务器没有找到目标资源的当前表示或不愿意透露存在的表示。”

                然后检查这里给出的文件位置:

                【讨论】:

                  【解决方案13】:

                  我刚刚在我的项目中解决了这个问题。原来我的连接字符串有错字并且与有效的数据库身份验证不同。证书。我犯了一个愚蠢的错误,希望其他人通过阅读本文可以节省时间。

                  【讨论】:

                    猜你喜欢
                    • 1970-01-01
                    • 1970-01-01
                    • 1970-01-01
                    • 2020-10-03
                    • 2017-10-21
                    • 1970-01-01
                    • 2018-04-07
                    • 2019-10-14
                    • 1970-01-01
                    相关资源
                    最近更新 更多