2014-10-28 26 views
0

我有以下的Web應用程序的結構:如何在Spring MVC的應用程序中打開彈出

enter image description here

addTerminal.jsp我寫如下:

.... 
<a href="#" class="open-map" onclick="showMap(55,22)">show map</a> 
... 
function showMap(lat,lng) { 
     window.open('map.html?lat='+lat+'&lng='+lng, 'map', 'width=600,height=400'); 
    } 
.... 

但由於客戶端不能訪問到WEB-INF文件夾我看到404點擊時href

你能否建議解決方法如何解決我的問題?

我想我可以把map.html放到webapp文件夾中,但我認爲存在另一個修復。 應用技術堆棧:

Tomcat + Hibernate + SpringMVC

的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> 

    <listener> 
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
    </listener> 

    <listener> 
     <listener-class> 
      org.springframework.web.context.request.RequestContextListener 
     </listener-class> 
    </listener> 

    <context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>/WEB-INF/spring/webContext.xml</param-value> 
    </context-param> 
    <!-- Spring MVC --> 
    <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/webContext.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> 

    <!-- Spring Security --> 
    <filter> 
     <filter-name>springSecurityFilterChain</filter-name> 
     <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> 
    </filter> 

    <filter-mapping> 
     <filter-name>springSecurityFilterChain</filter-name> 
     <url-pattern>/*</url-pattern> 
    </filter-mapping> 

    <filter> 
     <filter-name>charsetFilter</filter-name> 
     <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> 
     <init-param> 
      <param-name>encoding</param-name> 
      <param-value>UTF-8</param-value> 
     </init-param> 
     <init-param> 
      <param-name>forceEncoding</param-name> 
      <param-value>true</param-value> 
     </init-param> 
    </filter> 
    <filter-mapping> 
     <filter-name>charsetFilter</filter-name> 
     <url-pattern>/*</url-pattern> 
    </filter-mapping> 

</web-app> 
+0

你需要一個訪問路徑添加到彈出。將它放入網絡inf中將會導致無法訪問。將它放在webapp目錄中,並確保所有請求都沒有被轉發到spring調度器servlet,而是.html不被調度器處理。或者,將.mtml文件添加一個mvc:資源,然後您可以將它留在web-inf中。 – 2014-10-28 10:16:51

+0

你可以請你發佈你的網頁配置嗎? web.xml或java類取決於您使用的是哪個版本。你也可以發佈你的春季調度xml配置或javaconfig?這樣我可以給你一個你的用例的答案。 – 2014-10-28 10:21:04

+0

@Kevin Bayes主題更新 – gstackoverflow 2014-10-28 10:22:45

回答

0

您可以使用MVC:資源標記加載你考慮資源的項目。

<mvc:resources location="/web-inf/<path to html file>" mapping="<url context in a browser>" cache-period="86400"/> 

參考:http://docs.spring.io/spring/docs/4.1.2.BUILD-SNAPSHOT/spring-framework-reference/htmlsingle/#mvc-config-static-resources

+0

我應該在** **中寫入什麼內容? – gstackoverflow 2014-10-28 10:35:28

+0

如果您需要資源在/app/maps/map.html可用,那麼應該去那裏。位置應該有/WEB-INF/pages/member/createCompany/map.html。 – 2014-10-28 10:40:37

+0

得到了這個工作了嗎? – 2014-10-28 11:22:24

2

你只需要創建一個控制器來處理請求map.html

類似的東西:

@RequestMapping("/map.html") 
public String popup(@RequestParam("lat") String lat, @RequestParam("lng") String lng){ 
    // your code here... 
    return "map"; 
} 
+0

這可能不起作用。根據使用的視圖解析器,這可能永遠不會發送htm l文件。可以查找web-inf根目錄中不存在的map.jsp。另請注意,他正在使用JavaScript作爲參數。所以不需要處理參數。 – 2014-10-28 11:19:20

+0

它的工作原理。但你確定這是最好的解決方案嗎? – gstackoverflow 2014-10-28 18:31:41

+0

@gstackoverflow呃......你的'map.html'就像其他所有的頁面一樣,爲什麼你不想像其他的那樣處理它呢? IMO在彈出窗口或主窗口中顯示它只是一個細節... – davioooh 2014-10-29 15:59:02

相關問題