2013-02-25 162 views
2

我提到了很多帖子,但仍無法解決此問題。org.springframework.web.servlet.PageNotFound - 找不到具有URI的HTTP請求的映射

enter image description here

我試圖把這個CSS文件夾中的WEB-INF或視圖中,文件夾以及。
但仍然風格不反映在視圖頁面。

這裏是我的servlet-context.xml的

<?xml version="1.0" encoding="UTF-8"?> 
<beans:beans xmlns="http://www.springframework.org/schema/mvc" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:beans="http://www.springframework.org/schema/beans" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd 
     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"> 

    <resources mapping="/resources/**" location="/resources/" /> 

    <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <beans:property name="prefix" value="/WEB-INF/views/" /> 
     <beans:property name="suffix" value=".jsp" /> 
    </beans:bean> 

    <context:component-scan base-package="ctc.event.control" /> 

</beans:beans> 

這是我的web.xml

<?xml version="1.0" encoding="UTF-8"?> 
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> 

    <!-- The definition of the Root Spring Container shared by all Servlets and Filters --> 
    <context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>/WEB-INF/spring/root-context.xml</param-value> 
    </context-param> 

    <!-- Creates the Spring Container shared by all Servlets and Filters --> 
    <listener> 
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
    </listener> 

    <!-- Processes application requests --> 
    <servlet> 
     <servlet-name>appServlet</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
     <init-param> 
      <param-name>contextConfigLocation</param-name> 
      <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value> 
     </init-param> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 

    <servlet-mapping> 
     <servlet-name>appServlet</servlet-name> 
     <url-pattern>/</url-pattern> 
    </servlet-mapping> 

</web-app> 

這是我的樣式表ExpenseDetailsS​​tyles.css

#ItemDiv1_Table1 { 
    border: 1px solid black; 
} 

#ItemDiv1Table2 { 
    width: 20%; 
    float: right; 
    font-size:30px; 
} 

和我的看法頁。

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
    pageEncoding="ISO-8859-1"%> 
<%@ include file="TagIncludes.jsp" %> 
<!DOCTYPE html> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
<title>Expense Details</title> 
<link href='<c:url value="/resources/css/ExpenseDetailsStyles.css" />' rel="stylesheet" type="text/css" media="screen" /> 
<script type='text/javascript' src="../js/jquery-1.9.0.js"></script> 
<script type="text/javascript"></script> 
</head> 
<body> 
    <form:form name="ExpenseDetails" method="Post" 
     action="ExpenseDetailsForm.html"> 
     <div id="ItemDiv1"> 
      <table> 
       <tr> 
        <td> 
         <table id="ItemDiv1_Table1"> 
          <tr> 
           <td>Item</td> 
           <td><input type="text" name="Item1" id="Item1" required /></td> 
          </tr> 
          <tr> 
           <td>Expense in Rs</td> 
           <td><input type="text" name="ItemValue1" id="ItemValue1" ></td> 
          </tr> 
         </table> 
        </td> 
        <td> 
         <table id="ItemDiv1_Table2"> 
          <tr> 
           <td>Edit</td> 
          </tr> 
         </table> 
        </td> 
       </tr> 
      </table> 
     </div> 
    </form:form> 
</body> 
</html> 

這裏是控制器

@Controller 
public class ExpenseFormController { 

    @RequestMapping(value = "/ExpenseDetailsForm.html", method = RequestMethod.GET) 
    public String openForm() { 
     return "ExpenseDetailsForm"; 

    } 

    @RequestMapping(value = "/ExpenseDetailsForm.html", method = RequestMethod.POST) 
    public String submitForm() { 
     return null; 

    } 
} 

堆棧跟蹤不是一個錯誤,但警告。

WARN:org.springframework.web.servlet.PageNotFound - 未發現HTTP請求與URI映射[/計算器/ <c:url value="css/ExpenseDetailsStyles.css" />]在DispatcherServlet的名爲 'appServlet'

我認爲有一些我的uri在查看頁面時遇到了問題,我試着用不同的方式改變它。 任何人都可以請幫我改正uri並反映視圖頁面上的樣式嗎?
如果需要任何其他相關信息,請發表評論。

+0

您可能需要添加你所遇到的問題提供更多的信息?你可以附加你的註釋控制器嗎? – RoryB 2013-02-25 15:55:13

+0

你的問題到底是什麼? – KyelJmD 2013-02-25 15:57:15

+0

@KyelJmD查看頁面中的uri可能是錯誤的。我不知道什麼是錯的。在過去的一天裏受到攻擊。 – Freakyuser 2013-02-25 16:00:32

回答

6

您有以下

<servlet-mapping> 
    <servlet-name>appServlet</servlet-name> 
    <url-pattern>*.css</url-pattern> 
</servlet-mapping> 

<servlet-mapping> 
    <servlet-name>appServlet</servlet-name> 
    <url-pattern>*.js</url-pattern> 
</servlet-mapping> 

映射一些資源到春節servlet的,但你沒有任何控制器處理方法爲他們服務了。您應該刪除上述servlet-mapping s並將您的css資源置於/resources/cssjs資源中/resources/js。由於<mvc:resources>元素,Spring會知道從那裏自動獲取它們。

確保還要在HTML文件中更改腳本和CSS的硬編碼位置。

而且,在這條線

<link href='<c:url value="/resources/css/ExpenseDetailsStyles.css" />' ... /> 

使用雙引號"。您可能還需要重構這個

<c:url>標籤將會把值放入變量myvar那麼這將是你的<link>標籤可用。

你也需要這條線在你的JSP的頂部,告訴它你需要JSTL標籤:

<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%> 
+0

我已經刪除了'css'和'js'的'servlet-mapping'。我有這個,''在html中。它是否正確? – Freakyuser 2013-02-26 07:17:05

+0

順便說一下,我們討論的'resources'是'src/main/webapp'中的'resources',而不是'src/main /',我說得對嗎? – Freakyuser 2013-02-26 07:18:30

+0

我認爲它應該是'並在'src/main/webapp'中 – 2013-02-26 13:34:12

0

在你上下文文件,添加以下內容:

<mvc:resources mapping="/resources/**" location="/WEB-INF/resources/" /> 

這增加了一個靜態的路徑/資源/。只需將您的內容放在那裏。

+0

謝謝你的回答,我已經在我的servlet-context.xml中有了它。我已經在上面發佈了它。 – Freakyuser 2013-02-25 16:04:43

相關問題