`
dwj147258
  • 浏览: 192020 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

maven + jetty项目不能访问到正确路径的html页面

阅读更多

j今天部署了一个maven项目具体的配置如下:

spring-jetty.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

	<bean id="Server" class="org.eclipse.jetty.server.Server"
		init-method="start" destroy-method="stop">
		<property name="connectors">
			<list>
				<bean class="org.eclipse.jetty.server.nio.SelectChannelConnector">
					<property name="port" value="80" />
					<!--  <property name="maxIdleTime" value="30000" />
					<property name="requestHeaderSize" value="8192" />-->
				</bean>
			</list>
		</property>
		<property name="handler">
			<bean id="handlers" class="org.eclipse.jetty.server.handler.HandlerList">
				<property name="handlers">
					<list>
						<bean id="omcWeb" class="org.eclipse.jetty.webapp.WebAppContext">
							<property name="contextPath" value="/" />
							<property name="descriptor" value=".\src\webapp\WEB-INF\web.xml" />
							<!-- <property name="war" value="." /> -->
							<property name="resourceBase" value=".\src\webapp" />
							<property name="parentLoaderPriority" value="true" />
							<property name="logUrlOnStart" value="true" />
						</bean>
						<bean class="org.eclipse.jetty.server.handler.DefaultHandler"/>
					</list>
				</property>
			</bean>
		</property>
	</bean>
</beans>

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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">

  <display-name>ExpressDoor2</display-name>

  <welcome-file-list>

    <welcome-file>html/index.html</welcome-file>

  </welcome-file-list>

  <servlet>  

     <servlet-name>spring</servlet-name>  

      <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

       <init-param>  

            <param-name>contextConfigLocation</param-name>  

            <param-value>classpath:config/spring-servlet.xml</param-value>  

        </init-param>  

      <load-on-startup>1</load-on-startup>  

  </servlet>

  <servlet-mapping>  

      <servlet-name>spring</servlet-name>  

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

  </servlet-mapping>

  <context-param>  

      <param-name>contextConfigLocation</param-name>  

      <param-value>classpath:config/applicationContext.xml</param-value>  

  </context-param>

</web-app> 

 

applicationContext.xml

 

<?xml version="1.0" encoding="UTF-8"?>
  <beans xmlns="http://www.springframework.org/schema/beans"  
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
          xmlns:context="http://www.springframework.org/schema/context"
          xmlns:jms="http://www.springframework.org/schema/jms"
          xmlns:amq="http://activemq.apache.org/schema/core"
        xsi:schemaLocation="  
        	  http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core-5.8.0.xsd
              http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd  
              http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-3.0.xsd
              http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd">  
    <context:annotation-config/>
    <bean class = "org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" />
	<import resource="hibernate.xml"/>
	
  </beans>

 

 

spring-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd 
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd ">
	<mvc:resources location="/" mapping="/**/*.html"/> 
	<mvc:resources location="/" mapping="/**/*.js"/>
	<mvc:resources location="/" mapping="/**/*.jsp"/>
	<mvc:resources location="/" mapping="/**/*.css"/>
	<mvc:resources location="/" mapping="/**/*.jpg"/>
	<mvc:resources location="/" mapping="/**/*.woff"/>
	<mvc:resources location="/" mapping="/**/*.ttf"/>
	<mvc:resources location="/" mapping="/**/*.png"/>
	 <context:component-scan
			base-package="main.java">
    </context:component-scan>
 	<mvc:annotation-driven/>
   <mvc:default-servlet-handler/>
	<bean class ="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" >
      <property name="messageConverters">
            <list>
                <bean
                    class="org.springframework.http.converter.StringHttpMessageConverter">
                    <property name="supportedMediaTypes">
                        <list>
                            <value>text/plain;charset=UTF-8</value>
                            <value>text/html;charset=UTF-8</value>
                        </list>
                    </property>
                </bean>
                <bean id="mappingJacksonHttpMessageConverter"
                    class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
                    <property name="supportedMediaTypes">
                        <list>
                            <value>application/json;charset=UTF-8</value>
                            <value>text/html;charset=UTF-8</value>
                        </list>
                    </property>
                </bean>
            </list>
        </property>
</bean>
  <!-- SpringMVC上传文件时,需要配置MultipartResolver处理器 -->  
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">  
        <property name="defaultEncoding" value="UTF-8"/>  
        <!-- 指定所上传文件的总大小不能超过200KB。注意maxUploadSize属性的限制不是针对单个文件,而是所有文件的容量之和 -->  
        <property name="maxUploadSize" value="2000000"/>  
    </bean>  
      
    <!-- SpringMVC在超出上传文件限制时,会抛出org.springframework.web.multipart.MaxUploadSizeExceededException -->  
    <!-- 该异常是SpringMVC在检查上传的文件信息时抛出来的,而且此时还没有进入到Controller方法中 -->  
    <bean id="exceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">  
        <property name="exceptionMappings">  
            <props>  
                <!-- 遇到MaxUploadSizeExceededException异常时,自动跳转到/WEB-INF/jsp/error_fileupload.jsp页面 -->  
                <prop key="org.springframework.web.multipart.MaxUploadSizeExceededException">error_fileupload</prop>  
            </props>  
        </property>  
    </bean>
</beans>  

 完成后启动项目,无论输入什么路径都不能访问到html,找了半天原来是spring-jetty.xml配置文件中配置server的handler属性中的handlers中有一个properties:resourceBase这个属性应该配置正确的放web.xml

的上一级的上一级目录,如

如果我的web文件配置为:.\src\webapp\WEB-INF\web.xml

那么我的resourceBase就应该为:.\src\webapp

0
0
分享到:
评论

相关推荐

    Maven依赖包(用于博客项目)

    为了在项目中使用这些依赖,开发者需要将`repository(2)`中的内容复制到Maven的本地仓库路径(通常是`~/.m2/repository`),或者通过Maven的`install`命令将其安装到本地仓库。之后,在`pom.xml`文件中正确地声明...

    SSM项目的静态页面

    解压这个压缩包后,你可以按照提供的安装说明将静态页面集成到SSM项目中,确保所有资源路径正确,并配置好视图解析器,以便在运行项目时能够正确显示静态页面。同时,也要注意保持静态资源的更新和维护,以提供最佳...

    sshe项目部署

    - 在命令提示符中执行`mvn jetty:run`,确保路径正确且网络畅通。 - 浏览器访问`http://localhost:8080/sshe`进行测试。 - **第二种部署方式**(使用MyEclipse): - **前提条件**:MyEclipse 10或以上版本。 -...

    Java web项目-高校学生选课系统项目源码

    开发者需要配置服务器环境,包括数据库连接、应用上下文路径等,确保项目能正常运行。 通过分析这个"高校学生选课系统项目源码",开发者可以学习到从需求分析、设计、编码、测试到部署的全过程,提升对JavaWeb开发...

    增删改查,保存,查看,拦截

    创建Java Web项目时,我们需要选择"New Project",然后在项目类型中选择"Web Application",接着设置项目名称和路径,最后选择构建工具,这里我们使用的是Maven。Maven是一个项目管理工具,可以自动管理依赖,简化...

    基于springboot搭建属于自己的博客网站.zip

    自动配置是SpringBoot的一大亮点,它可以根据项目中的类路径自动配置Spring容器。这样,开发者无需编写大量XML配置,只需通过注解就能实现应用程序的配置。 描述中提到"包含数据库文件",这意味着项目可能使用了...

    图解JSP环境安装配置

    访问`http://localhost:8080/你的项目名/index.jsp`,如果一切配置正确,你应该能看到"Hello, World!"。 至此,你已经成功地搭建了JSP开发环境。随着进一步的学习,你可能还需要了解Servlet、JSTL、EL表达式、MVC...

    毕业设计源码之基于Springboot的BUG管理平台.zip

    这是一个基于Springboot的BUG管理平台的毕业设计源码项目,主要涵盖了Java编程语言的应用、前后端交互以及项目部署的相关知识。下面将详细讲解这个项目所涉及的技术栈和关键点。 首先,Springboot是Spring框架的一...

    基于ssm+mysql的个性化电子相册设计源码数据库.zip

    - 使用Maven进行项目管理,确保依赖库的正确引入和版本管理。 - 前端采用HTML、CSS和JavaScript,利用Bootstrap或自定义样式提升页面美观度和响应式布局。 - 后端采用RESTful API设计,通过JSON进行数据交换,...

    基于springboot开发的前后端分离项目-源码

    - 自动配置:Spring Boot会根据项目类路径下的jar依赖自动配置相应的bean。 - 内嵌式容器:Spring Boot支持内嵌Tomcat、Jetty或Undertow等HTTP服务器,无需额外打包成war文件部署。 2. **前后端分离概念**: - ...

    javax.servlet.jsp.jar

    当你在开发或者运行一个基于JSP的项目时,如果遇到“找不到该jar包”的异常,可能是因为你的开发环境或应用服务器缺少了这个必要的依赖。 Java Servlet API提供了服务端的编程模型,允许开发者编写运行在Web服务器...

    基于Java的jfinal cms Java信息咨询网站.zip

    - **部署**:通过Tomcat、Jetty等Web服务器部署JFinal CMS,确保服务器配置正确,保证项目稳定运行。 - **监控与优化**:使用日志分析工具监控系统运行状态,进行性能调优,确保网站高效响应。 总结,基于Java的...

    Ecology二次开发操作说明V0.4

    5. 配置开发环境:根据文档指示配置项目路径、类路径和环境变量,确保所有依赖库都能正确加载。 二、代码结构理解 1. 了解项目结构:Ecology系统通常包含多个模块,每个模块负责不同的功能,熟悉这些模块及其相互...

    springboot-demo

    SpringBoot是Spring框架的一个简化...通过"springboot-demo"项目,你可以学习到如何设置一个基本的SpringBoot项目结构,以及如何编写和组织测试代码。这是一个很好的起点,可以帮助你深入理解SpringBoot的特性和优势。

    springboot-03-web.zip

    2. `pom.xml`:Maven的项目对象模型(Project Object Model)文件,它定义了项目依赖、构建过程等信息。在Spring Boot项目中,我们可以通过在`pom.xml`中声明Spring Boot的父依赖来简化配置,同时添加所需的Spring ...

    The Grails Framework - Reference Documentation

    - **部署至Maven仓库**:将项目打包并发布到Maven仓库中。 - **插件依赖**:处理Grails插件之间的依赖关系。 #### 四、命令行工具 ##### 4.1 创建Gant脚本 - **编写Gant脚本**:使用Groovy语法编写脚本文件。 - **...

    基于SSM的人事管理系统

    7. **测试**:项目开发过程中,单元测试、集成测试和系统测试是必不可少的环节,以确保每个功能的正确性和系统的稳定性。JUnit和Mockito等工具可以帮助进行Java代码的测试,而Selenium等工具则可用于前端的自动化...

    JSP开发环境配置文档

    4. **Maven或Gradle集成**:对于大型项目,推荐使用构建工具管理依赖。配置相应的pom.xml或build.gradle文件,确保所有库正确导入。 5. **版本兼容性**:确保JDK、Tomcat和IDE之间的版本兼容,避免因版本不匹配导致...

    基于SpringBoot开发的校内信息共享平台-源码

    【SpringBoot概述】 SpringBoot是由Pivotal团队提供的全新框架,其设计目标是用来简化新Spring应用的初始搭建以及开发过程。...这不仅有助于提升SpringBoot的使用技能,还能为开发类似项目提供参考和实践基础。

    springboot+shiro开发的公司网站源码

    - **pom.xml**:Maven或Gradle的项目配置文件,定义了项目的依赖关系。 - **src/main/java**:Java源代码目录,包含SpringBoot启动类、Controller、Service、DAO以及Shiro的相关配置和过滤器。 - **src/main/...

Global site tag (gtag.js) - Google Analytics