Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
找不到org.springframework.web.servlet.PageNotFound,因为war中未包含控制器类_Spring_Jsp_Spring Mvc - Fatal编程技术网

找不到org.springframework.web.servlet.PageNotFound,因为war中未包含控制器类

找不到org.springframework.web.servlet.PageNotFound,因为war中未包含控制器类,spring,jsp,spring-mvc,Spring,Jsp,Spring Mvc,(请参阅下面的更新) 我已经为这个问题挣扎了很久了。 我正在关注John Purcival的Spring MVC框架教程。 我已经完全按照教程系列中所述设置了一个DispatcherServlet、一个Controller和一个ViewResolver,但是当我运行应用程序时,它会给我以下错误: org.springframework.web.servlet.PageNotFound noHandlerFound 我已经经历了无数与同一问题相关的问题,但迄今为止,没有一个对我有效。我现在束手无策

(请参阅下面的更新)

我已经为这个问题挣扎了很久了。 我正在关注John Purcival的Spring MVC框架教程。 我已经完全按照教程系列中所述设置了一个
DispatcherServlet
、一个
Controller
和一个
ViewResolver
,但是当我运行应用程序时,它会给我以下错误:

org.springframework.web.servlet.PageNotFound noHandlerFound

我已经经历了无数与同一问题相关的问题,但迄今为止,没有一个对我有效。我现在束手无策

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" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>spring-tutorial-50</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>/</url-pattern>
  </servlet-mapping>
</web-app>
<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-4.3.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">


    <context:component-scan base-package="com.me.spring.web.controllers">
    </context:component-scan>
    <mvc:annotation-driven></mvc:annotation-driven>

    <bean id="jspViewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/jsps/"></property>
        <property name="suffix" value=".jsp"></property>
    </bean>
</beans>
/WebContent/WEB-INF/jsps/home.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
Hi there!

Session: <%= session.getAttribute("name") %> <p/>

</body>
</html>

在此处插入标题
你好!
会话:

更新

我通过以下步骤更改了服务器的部署路径:

在Eclipse中,您可以将该部署文件夹更改为其他文件夹

  • 删除分配给tomcat的所有项目,否则您将无法更改设置(右键单击服务器/添加和删除…)
  • 进行清理(右键单击服务器/清理…)
  • 双击服务器以打开配置页面
  • 在“服务器位置”部分,选择“使用自定义位置”,并指定您选择的文件夹作为服务器路径。你可以走了 “wtpwebapps”作为部署文件夹。我通常会设置一些 “C:\virtualTomcat”作为服务器路径
  • 保存文件,进行另一次清理,然后将项目添加回服务器(右键单击服务器/添加和删除…)
我现在发现OffersController没有编译;换言之:

${serverDeploymentDirectory}/wtpwebapps/${projectName}/WEB-INF/classes/com/me/spring/WEB/controllers/


是空的

我可以通过完成以下步骤来解决此问题:

  • 右键单击项目。单击
    Properties->Deployment Assembly
    。从展开程序集中删除带圆圈的条目
  • 单击
    服务器
    选项卡。单击服务器名称左侧的小箭头。这将显示已部署项目的列表。右键单击有问题的项目,然后选择
    Clean Module Work Directory

  • 选择项目的根目录。从工具栏中,选择
    Project Clean

  • 右键单击项目的根目录<代码>运行方式->在服务器上运行


  • 我通过完成以下步骤解决了此问题:

  • 右键单击项目。单击
    Properties->Deployment Assembly
    。从展开程序集中删除带圆圈的条目
  • 单击
    服务器
    选项卡。单击服务器名称左侧的小箭头。这将显示已部署项目的列表。右键单击有问题的项目,然后选择
    Clean Module Work Directory

  • 选择项目的根目录。从工具栏中,选择
    Project Clean

  • 右键单击项目的根目录<代码>运行方式->在服务器上运行


  • servlet被映射到
    /
    。控制器映射到
    /
    。webapp似乎是作为根webapp部署的(请确认),因此也映射到容器中的
    /
    。那么,为什么要使用
    /offers/
    访问控制器?转到
    http://localhost:8081/
    。尝试访问“”,因为我的应用程序的上下文根是“offers”。我尝试了“”,但仍然得到了404,servlet被映射到
    /
    。控制器映射到
    /
    。webapp似乎是作为根webapp部署的(请确认),因此也映射到容器中的
    /
    。那么,为什么要使用
    /offers/
    访问控制器?转到
    http://localhost:8081/
    。尝试访问“”,因为我的应用程序的上下文根是“offers”。我试过“”但还是得到了404
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
    Hi there!
    
    Session: <%= session.getAttribute("name") %> <p/>
    
    </body>
    </html>