【发布时间】:2016-04-13 08:31:44
【问题描述】:
我有一个 spring mvc 应用程序在 tomcat 上运行良好。
但是当我尝试使用 weblogic 运行时不要重定向。
例如:
我的jsp有一个链接:<a href="new">New User</a>
我的控制器捕捉到了 url:
@RequestMapping(value = { "/new" }, method = { org.springframework.web.bind.annotation.RequestMethod.GET })
public ModelAndView newUser() {
ModelAndView model = new ModelAndView("UserForm");
model.addObject("user", new User());
return model;
}
这在 tomcat 上运行,但是当我尝试使用 weblogic 时,他重定向到“http://localhost:7001/new”并且必须是“http://localhost:7001/HibernateJavaBased/new”
如何设置 weblogic 服务器?
更新 1:我的 App 是 java config 这是初始化程序
public class SpringWebAppInitializer implements WebApplicationInitializer {
public void onStartup(ServletContext container) throws ServletException {
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
ctx.register(ApplicationContextConfig.class);
ctx.setServletContext(container);
ServletRegistration.Dynamic servlet = container.addServlet("dispatcher", new DispatcherServlet(ctx));
servlet.setLoadOnStartup(1);
servlet.addMapping("/");
System.out.println(ctx.getServletContext().getContextPath());
servlet.setInitParameter("contextClass", ctx.getClass().getName());
container.addListener(new ContextLoaderListener(ctx));
}
}
还有 AppConfig:
@Configuration
@EnableWebMvc
@ComponentScan({ "net.codejava.spring" })
@EnableTransactionManagement
public class ApplicationContextConfig extends WebMvcConfigurerAdapter {
@Bean(name = { "viewResolver" })
public InternalResourceViewResolver getViewResolver() {
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setPrefix("/WEB-INF/views/");
viewResolver.setSuffix(".jsp");
return viewResolver;
}
【问题讨论】: