在GAE上没有找到使用Spring3 MVC + Maven2的映射 [英] No mapping found using Spring3 MVC + Maven2 on GAE

查看:131
本文介绍了在GAE上没有找到使用Spring3 MVC + Maven2的映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这是我的web.xml

 < servlet> 
< servlet-name>调度程序< / servlet-name>
< servlet-class> org.springframework.web.servlet.DispatcherServlet< / servlet-class>
< init-param>
< param-name> contextConfigLocation< / param-name>
< param-value>
/WEB-INF/spring/webmvc-config.xml
< / param-value>
< / init-param>
1< / load-on-startup>
< / servlet>

< servlet-mapping>
< servlet-name>调度程序< / servlet-name>
< url-pattern> / *< / url-pattern>
< / servlet-mapping>

这是我的SpringMVC配置文件

 < context:annotation-config /> 

< context:component-scan base-package =com.mypackage/>

< mvc:annotation-driven />

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

这是我的控制器:

<$ p $ @Controller
@RequestMapping(value =/ hello)
public class HelloController {
@RequestMapping(method = RequestMethod.GET)
public String helloGet(ModelMap map){
map.put(name,seb!);
返回hello;


$ / code $ / pre

这是我的视图位于webapp / WEB- INF / jsp / view / hello.jsp

 <%@ taglib prefix =curi =http:// java.sun.com/jsp/jstl/core%> 
<%@ taglib prefix =fmturi =http://java.sun.com/jsp/jstl/fmt%>
<%@ taglib prefix =fnuri =http://java.sun.com/jsp/jstl/functions%>
<!DOCTYPE HTML PUBLIC - // W3C // DTD HTML 4.01 Transitional // EN
http://www.w3.org/TR/html4/loose.dtd\">
< html>
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = UTF-8>
< title> Hello Controller< / title>
< / head>
< body>
< h1> Hello $ {name}!< / h1>
< / body>
< / html>

这是我的pom包含依赖到SpringMVC 3.0.3,servlet-api 2.5,jstl 1.2



我一直在收到

 警告:找不到HTTP映射使用名为'dispatcher'的DispatcherServlet中的URI [/WEB-INF/jsp/view/hello.jsp]的请求

当我打localhost:8080 / hello时,我找不到原因。是由于GAE还是我在某些配置中丢失了任何内容?



更新
如果我发送来自/ app / *到Spring Dispatcher,像这样改变我的web.xml:

 < servlet-mapping> 
< servlet-name>调度程序< / servlet-name>
< url-pattern> / app / *< / url-pattern>
< / servlet-mapping>`

它可以工作,但我只想使用着陆页并使用应用程序的根目录

解决方案

我过去遇到过这个问题。如果我记得正确,它在部署时运行正常,但在开发服务器上失败。我的解决方案是将调度程序servlet映射到 / app / * ,而不是 / *



这会导致应用程序中所有URL路径中的 / app >。如果您想摆脱这种情况,请使用URL重写。



web.xml中

 < filter> 
< filter-name> urlRewriteFilter< / filter-name>
< filter-class> org.tuckey.web.filters.urlrewrite.UrlRewriteFilter< / filter-class>
< / filter>

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

urlrewrite.xml

 <?xml version =1.0encoding =utf-8?> 
<!DOCTYPE urlrewrite PUBLIC - // tuckey.org//DTD UrlRewrite 3.0 // EN
http://tuckey.org/res/dtds/urlrewrite3.0.dtd\"> ;
< urlrewrite default-match-type =wildcard>
< rule>
< from> /< / from>
< to> / app /< / to>
< / rule>
< rule>
< from> / _ ah / **< / from>
< to> / _ ah / $ 1< / to>
< / rule>
< rule>
< from> / **< / from>
< to> / app / $ 1< / to>
< / rule>
<出站规则>
< from> / _ ah / **< / from>
< to> / _ ah / $ 1< / to>
< /出站规则>
<出站规则>
< from> / app / **< / from>
< to> / $ 1< / to>
< /出站规则>
< / urlrewrite>


I'm getting a weird issue trying to integrate Spring MVC and Maven in a Google AppEngine webapp.

This is my web.xml

 <servlet>  
        <servlet-name>dispatcher</servlet-name>  
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
                /WEB-INF/spring/webmvc-config.xml
            </param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>  
   </servlet>  

   <servlet-mapping>  
      <servlet-name>dispatcher</servlet-name>  
      <url-pattern>/*</url-pattern>  
   </servlet-mapping>

this is my SpringMVC config file

<context:annotation-config />

<context:component-scan base-package="com.mypackage" />

<mvc:annotation-driven/>

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

this is my controller:

@Controller
@RequestMapping(value = "/hello")
public class HelloController {
     @RequestMapping(method = RequestMethod.GET)  
     public String helloGet(ModelMap map) {  
            map.put("name", "seb!");  
            return "hello";  
     }  
}

and this is my view located at webapp/WEB-INF/jsp/view/hello.jsp

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!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>Hello Controller</title>
    </head>
    <body>
        <h1>Hello ${name}!</h1>
    </body>
</html>

and this is my pom contains dependencies to SpringMVC 3.0.3, servlet-api 2.5, jstl 1.2

I'm keeping getting

WARNING: No mapping found for HTTP request with URI [/WEB-INF/jsp/view/hello.jsp] in DispatcherServlet with name 'dispatcher'

when I hit localhost:8080/hello and I can't figure out why. Is it due to GAE or am I missing anything in some config?

Update: If I dispatch the URL coming from /app/* to Spring Dispatcher, changing my web.xml like this:

<servlet-mapping>  
      <servlet-name>dispatcher</servlet-name>  
      <url-pattern>/app/*</url-pattern>  
   </servlet-mapping>`

it'll work, but I just want to use landing pages and use the root of the app

解决方案

I've faced this issue in the past. If I recall correctly it worked properly when deployed, but failed on the development server. My solution was to map the dispatcher servlet to /app/* instead of /*.

That results /app in all the URL paths in your application. If you want to get rid of this, use URL rewriting.

In web.xml:

<filter>
    <filter-name>urlRewriteFilter</filter-name>
    <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
</filter>

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

And urlrewrite.xml:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 3.0//EN"
        "http://tuckey.org/res/dtds/urlrewrite3.0.dtd">
<urlrewrite default-match-type="wildcard">
    <rule>
        <from>/</from>
        <to>/app/</to>
    </rule>
    <rule>
        <from>/_ah/**</from>
        <to>/_ah/$1</to>
    </rule>
    <rule>
        <from>/**</from>
        <to>/app/$1</to>
    </rule>
    <outbound-rule>
        <from>/_ah/**</from>
        <to>/_ah/$1</to>
    </outbound-rule>
    <outbound-rule>
        <from>/app/**</from>
        <to>/$1</to>
    </outbound-rule>
</urlrewrite>

这篇关于在GAE上没有找到使用Spring3 MVC + Maven2的映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆