2014-10-28 78 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

相关问题