1

I have a stupid problem I have no idea why this is happening - view resolution fails if I have slashes in my mapping; I have this controller:

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class PartialsController {

  @RequestMapping ("/views/partials/{view}") // Doesn't work!
  public String partial (@PathVariable ("view") String view) {
    System.out.println ("\n\nVIEW=\"" + view + "\"\n\n");
    return "partials/" + view;
  }

  @RequestMapping ("/partial-{view}-view") // Works!!!
  public String test (@PathVariable ("view") String view) {
    return partial (view);
  }

  @RequestMapping ("/views/partials/{view}/show.html") // Doesn't work!
  public String test2 (@PathVariable ("view") String view) {
    return partial (view);
  }
}

Full stack trace is here: http://pastebin.com/CXwYd9i3 here's the top of it (I see my system.out in every case):

[DEBUG] : Could not complete request
java.lang.NullPointerException
at java.net.URLEncoder.encode(URLEncoder.java:205)
at java.net.URLEncoder.encode(URLEncoder.java:171)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:474)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:378)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:669)
    ...

I'd really like to use the first method, it just makes more sense for what I'm doing; much thanks in advance for any help!

P.S. Forgot to add, this is my Java Config:

@Override
public void onStartup (ServletContext servletContext) throws ServletException {
  AnnotationConfigWebApplicationContext mvcContext = new AnnotationConfigWebApplicationContext ();
  mvcContext.register (MvcConfiguration.class);
  Dynamic dispatcher = servletContext.addServlet ("dispatcher", new DispatcherServlet (mvcContext));
  dispatcher.setLoadOnStartup (1);
  dispatcher.addMapping ("/");
}
4

2 に答える 2

0

私は実際にそれを理解し、応答を入力すると、JSPビューリゾルバーのセットアップに何か問題があると思いました。実際には次のものがありました。

@Bean (name = "jspViewResolver")
public ViewResolver jspViewResolver () {
  return new InternalResourceViewResolver () {
    {
      setPrefix ("/META-INF/resources/mev/views/");
      setSuffix (".jsp");
      setOrder (2);
      setExposeContextBeansAsAttributes (true);
    }
  };
}

META-INF の前に先頭のスラッシュがありませんでした。ええ、私は奇妙な場所で私の見解を持っています。とりあえずありがとう!

于 2013-08-06T15:42:14.020 に答える
0

これを試して:

 @Override
public void onStartup (ServletContext servletContext) throws ServletException {
  AnnotationConfigWebApplicationContext mvcContext = new AnnotationConfigWebApplicationContext ();
  mvcContext.register (MvcConfiguration.class);
  Dynamic dispatcher = servletContext.addServlet ("dispatcher", new DispatcherServlet (mvcContext));
  dispatcher.setLoadOnStartup (1);
  dispatcher.addMapping ("/*"); //<- It will dispatch all URLs, not only those which starts with /
}
于 2013-08-06T08:45:41.480 に答える