我有一个视图解析器:
<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
和控制器:
@RequestMapping(value = "/home", method = RequestMethod.GET)
public String loadPage(HttpServletRequest request,HttpServletResponse response, HttpSession session,ModelMap modelMap ) {
String langlayout = "eng";
UrlBasedViewResolver urlResolver = new UrlBasedViewResolver();
urlResolver.setPrefix("/WEB-INF/views/"+langlayout);
urlResolver.setSuffix(".jsp");
return "home/list.jsp";
}
点击jsp之后仍然在 WEB-INF / views / home / list 而不是 WEB-INF / views / eng / home / list <登记/> 如何定义自定义视图页面
答案 0 :(得分:1)
终于得到了我的问题的解决方案
<!-- Declare a view resolver -->
<bean class="com.project.controller.AppPortalViewResolver">
<property name="viewResolver" ref="viewResolver" />
</bean>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
<强> AppPortalViewResolver.class 强>
public class AppPortalViewResolver implements ViewResolver {
private ViewResolver viewResolver;
public void setViewResolver(ViewResolver viewResolver) {
this.viewResolver = viewResolver;
}
@Override
public View resolveViewName(String viewName, Locale locale) throws Exception {
/* do your logic to change the view name */
viewName = "ur_folder_structure";
return viewResolver.resolveViewName(viewName, locale);
}
答案 1 :(得分:0)
@RequestMapping(value = "/home", method = RequestMethod.GET)
public String loadPage(HttpServletRequest request,HttpServletResponse response, HttpSession session,ModelMap modelMap ) {
String langlayout = "eng";
return langlayout+"/home/list.jsp";
}