2017-07-24 72 views
0

我有3個jQuery選項卡。當我點擊主頁選項卡時,firefox控制檯顯示「GET http://localhost:8080/MedAI/jsp/homeTab.jsp [404 Not Found]」。
爲什麼?下面是index.jsp的在MedAI /網頁/ WEB-INF/JSP/homeTab.jsp NetBeans項目存在jquery標籤頁未找到

<div id="tabs"> 
<ul> 
    <li><a href="jsp/homeTab.jsp">Home</a></li> 
    <li><a href="<c:url value='jsp/geneNetworkTab' />">Gene Network</a></li> 
    <li><a href="<c:url value='jsp/diseaseNetworkTab' />">Disease Network</a></li> 
</ul> 
</div> 
    <script type="text/javascript"> 
     $(document).ready(function() { 
     $('#tabs') 
      .tabs() 
     });  
    </script> 

我homeTab.jsp代碼段。它只是顯示「你好世界」。

我用jstl方法和直接url方法試了一下,它們都帶和不帶.jsp擴展名。什麼都沒有爲什麼它找不到它?

調度-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:aop="http://www.springframework.org/schema/aop" 
     xmlns:tx="http://www.springframework.org/schema/tx" 
     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd 
     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd 
     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd"> 

    <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/> 

    <!-- 
    Most controllers will use the ControllerClassNameHandlerMapping above, but 
    for the index controller we are using ParameterizableViewController, so we must 
    define an explicit mapping for it. 
    --> 
    <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> 
     <property name="mappings"> 
      <props> 
       <prop key="index.htm">indexController</prop> 
      </props> 
     </property> 
    </bean> 

    <bean id="viewResolver" 
      class="org.springframework.web.servlet.view.InternalResourceViewResolver" 
      p:prefix="/WEB-INF/jsp/" 
      p:suffix=".jsp" /> 

    <!-- 
    The index controller. 
    --> 
    <bean name="indexController" 
      class="org.springframework.web.servlet.mvc.ParameterizableViewController" 
      p:viewName="index" /> 

</beans> 

的web.xml

<?xml version="1.0" encoding="UTF-8"?> 
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"> 
    <context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>/WEB-INF/applicationContext.xml</param-value> 
    </context-param> 
    <listener> 
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
    </listener> 
    <servlet> 
     <servlet-name>dispatcher</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
     <load-on-startup>2</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>dispatcher</servlet-name> 
     <url-pattern>*.htm</url-pattern> 
    </servlet-mapping> 
    <session-config> 
     <session-timeout> 
      30 
     </session-timeout> 
    </session-config> 
    <welcome-file-list> 
     <welcome-file>redirect.jsp</welcome-file> 
    </welcome-file-list> 
</web-app> 

回答

0

花了我幾天的研究和試驗和錯誤,但我終於明白了。我恨春天!這是我曾經使用過的最令人困惑的非直觀框架。

這裏是我的NetBeans項目結構:

enter image description here

的web.xml

<?xml version="1.0" encoding="UTF-8"?> 
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"> 
    <context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>/WEB-INF/applicationContext.xml</param-value> 
    </context-param> 
    <listener> 
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
    </listener> 
    <servlet> 
     <servlet-name>dispatcher</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
     <load-on-startup>2</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>dispatcher</servlet-name> 
     <url-pattern>*.htm</url-pattern> 
    </servlet-mapping> 
    <session-config> 
     <session-timeout> 
      30 
     </session-timeout> 
    </session-config> 
    <welcome-file-list> 
     <welcome-file>index.jsp</welcome-file> 
    </welcome-file-list> 
</web-app> 

我愚弄與周圍的url-pattern的試圖讓簡單的 「/」 工作,但不能。保持404未找到錯誤。

注意index.jsp是WEB-INF之外唯一的jsp。當您在瀏覽器中輸入「http://localhost:8084/MedAI/」時,這是着陸點。

它的土地,因爲

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

調度-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:aop="http://www.springframework.org/schema/aop" 
     xmlns:mvc="http://www.springframework.org/schema/mvc" 
     xmlns:tx="http://www.springframework.org/schema/tx" 
     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd 
     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd 
     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd 
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd 
     http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd"> 
    <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/> 
    <context:annotation-config /> 
    <context:component-scan base-package="com.tekknow.medai" /> 
    <mvc:annotation-driven /> 

    <bean id="viewResolver" 
      class="org.springframework.web.servlet.view.InternalResourceViewResolver" 
      p:prefix="/WEB-INF/jsp/" 
      p:suffix=".jsp" /> 
</beans> 

與任何的* .htm被髮送到調度員的servlet,因爲網絡的結束URL的存在。 XML網址模式。然後,viewResolver bean會說要在WEB-INF/jsp文件夾中查找名稱(減去.htm擴展名並加上.jsp擴展名)。

的index.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%> 
<!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=UTF-8"> 
     <title>MedAI - Medical Artifical Intelligence</title> 
     <script type="text/javascript" src="resources/js/jquery.js"></script>  
     <script type="text/javascript" src="resources/js/jquery-ui.js"></script> 
</script>   
     <link href="resources/css/jquery-ui.css" rel="stylesheet" type="text/css" /> 
     <link href="resources/css/medai.css" rel="stylesheet" type="text/css" /> 
    </head> 
    <body> 
    <div class="header"> 
     <h1>MedAI</h1> 
     <span class="version">V 1.0.0</span>    
    </div> 

    <div id="tabs"> 
    <ul> 
     <li><a href="home.htm">Home</a></li> 
     <li><a href="GeneNetwork.htm">Gene Network</a></li> 
     <li><a href="DiseaseNetwork.htm">Disease Network</a></li> 
    </ul> 
    </div> 
     <script type="text/javascript"> 
      $(document).ready(function() { 
      $('#tabs') 
       .tabs() 
      });  
     </script>  
    </body> 
</html> 

通知的URL與熱媒結束。正如我前面所說的,我嘗試了不使用.htm並在web.xml url-pattern中使用「/」,但它不起作用。

home.htm,GeneNetwork.htm和DiseaseNetwork.htm每個具有類似於此他們自己的控制器:

HomeController.java

package com.tekknow.medai.controller; 

import org.springframework.stereotype.Controller; 
import org.springframework.ui.ModelMap; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestMethod; 

@Controller 
@RequestMapping("/home.htm") 
public class HomeController { 

    @RequestMapping(method = RequestMethod.GET) 
    public String handleRequest(ModelMap modelMap) { 
     System.out.println("HomeController.handleRequest"); 
     return "home"; 
    } 
} 

此將其發送到針對home.jsp視圖。

回到Home.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%> 
<!DOCTYPE html> 
<html> 
    <head> 
     <title>Home</title> 
    </head> 
    <body> 
     <h1>MedAI Home</h1> 
    </body> 
</html> 

然後幾十個小時後,終於... enter image description here

希望這將節省大家的多次浪費時間!

1

jsp/homeTab.jsp < ----這個目錄中的文件夾WebPages,而不是它Web-INF

jsp的應位於您的的WebContent的根文件夾,而不是在Web-INFWeb-INF是Java類將被編譯的位置,將包含您的lib和您的項目描述文件web.xml

+0

是的。您可以將JSP放在web-inf中,但只有通過servlet和轉發才能訪問直接請求。它可以是有用的。 –

+0

我添加了我的web.xml和dispather-servlet.xml。請注意,index.jsp IS找到了。 redirect.jsp位於Web Pages文件夾下(NetBeans相當於Eclipse的WebContent),只是做了「response.sendRedirect(」index.htm「); – user3217883

+0

顯然index.htm被映射到/WEB-INF/jsp/index.jsp通過dispather-servlet.xml中的indexController和viewResolver。什麼是重擊系統?爲什麼Spring很受歡迎? – user3217883