我有一个 Spring MVC 应用程序,与 Tomcat 一起运行良好。
但是当我尝试使用 weblogic 运行时,不要重定向。
例如:
我的jsp有一个链接:<a href="new">New User</a>
我的 Controller 捕获网址:
@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:我的应用程序是java配置,这是初始化程序
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;
}
最佳答案
也许您已经在 tomcat 上配置了上下文根。您还可以使用文件 weblogic.xml 在 Web 逻辑中配置上下文根。如果您还没有文件 weblogic.xml,请在/WEB-INF/目录下创建一个新文件 weblogic.xml。
<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app
xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd
http://xmlns.oracle.com/weblogic/weblogic-web-app
http://xmlns.oracle.com/weblogic/weblogic-web-app/1.4/weblogic-web-app.xsd">
<wls:weblogic-version>12.2.1</wls:weblogic-version>
<wls:context-root>HibernateJavaBased</wls:context-root>
</wls:weblogic-web-app>
希望这有帮助
关于java - Weblogic 12.2.1,链接错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36592785/