當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
J2EE搭建Dynamic web SpringMVC工程404错误分析(一)
生活随笔
收集整理的這篇文章主要介紹了
J2EE搭建Dynamic web SpringMVC工程404错误分析(一)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
目錄結構如下:
自己寫的web.xml
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <display-name>Spring MVC Application</display-name> <servlet> <servlet-name>HelloWeb</servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> <init-param><param-name>contextConfigLocation</param-name><param-value>classpath:HelloWeb-servlet.xml</param-value></init-param><load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>HelloWeb</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <welcome-file-list><welcome-file>Test</welcome-file></welcome-file-list></web-app><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:HelloWeb-servlet.xml</param-value></init-param>
是指定自己的Spring配置的xml.
問題:
對于不指定的條件下,默認是就是[serveletname]-servlet.xml默認路徑是webcontent文件夾下面和web.xml同級就可以。但是有的時候會爆出不能找到[servletname]-servlet.xml;那么把該xml文件移到src文件夾下面就可以了。---- 這個問題暫時還沒有研究。
<init-param><param-name>contextConfigLocation</param-name><param-value>classpath:HelloWeb-servlet.xml</param-value></init-param>這個是配置請求文件的跳轉,也就是當有請求的時候直接跳轉Test,因為你的spring控制器配置如下:
MainController.ava代碼:
不添加會爆出404錯誤!!!!!就是自己制定請求的url ? ?--->?http://localhost:8080/twoDynamic/Web/Test
但是添加了空的Test文件:
不用使用全的url便可以請求。但是反而輸入全的url爆出了404:
這個原因可能:在spring控制器中已經添加了跳轉,所以沒有必要請輸入全url。
HelloWeb-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: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-4.0.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsdhttp://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd"><context:component-scan base-package="web.controller"></context:component-scan><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/jsp/" /> <property name="suffix" value=".jsp" /> </bean> </beans>總結
以上是生活随笔為你收集整理的J2EE搭建Dynamic web SpringMVC工程404错误分析(一)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 微擎及智能名片小程序安装步骤
- 下一篇: J2EE搭建Dynamic web Sp