Spring控制器返回双斜杠url



Spring控制器在URL中创建双斜杠,为什么?

例如,下面的控制器将创建一个URL,看起来像:"http://localhost/myapp//customer_home"或者如果登录失败,"http://localhost/myapp//login">

我正在使用springmvc 5.3.16下面标记了配置类,你好,世界级最小。

@Controller
public class LoginController {
@ModelAttribute("login")
public Login setLogin() {
return new Login();
}
@GetMapping("/login")
public String login(Login login) {
return "login";
}

@PostMapping(value="/login")
public String login(@ModelAttribute("login") final Login login, final Model model) {

// check login

if (loginOK) {
return  "redirect:customer_home"; 
} else {
model.addAttribute("error", "Login failed");
return "login";
}
}
public class SpringDispatcherConfig implements WebMvcConfigurer {
@Bean
public InternalResourceViewResolver resolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setViewClass(JstlView.class);
resolver.setPrefix("/WEB-INF/views/");
resolver.setSuffix(".jsp");
return resolver;
}

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry
.addResourceHandler("/resources/**")
.addResourceLocations("/resources/");
}
}
public class SpringDispatcherServletInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
static {
HibernateUtil.buildSessionFactory("hibernate.cfg.xml");
new SocketServer().start();
}
@Override
protected Class <?> [] getServletConfigClasses() {
return new Class[] {
SpringDispatcherConfig.class
};
}

@Override  
protected Class<?>[] getRootConfigClasses() {  
return null;
}  
@Override
protected String[] getServletMappings() {
return new String[] {
"/"
};
}
}

从application.properties(myapp(中的上下文路径中删除斜杠。

相关内容

  • 没有找到相关文章

最新更新