日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

J2EE搭建Dynamic web SpringMVC工程404错误分析(一)

發布時間:2023/12/19 javascript 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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代碼:

package web.controller;import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @Controller //@RequestMapping("/Web") public class MainController {@RequestMapping(value="/Test", method=RequestMethod.GET) public String returnJSP(){ return "MyWeb"; //JSP 名字 } } 控制器會將請求跳轉到Test,這也是問什么配置:

<init-param><param-name>contextConfigLocation</param-name><param-value>classpath:HelloWeb-servlet.xml</param-value></init-param>同時還需要添加一個Test空文件在webcontent下:

不添加會爆出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错误分析(一)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。