简体   繁体   中英

Weblogic 12.2.1, links error

i have an spring mvc application running well with tomcat.

But when i try run with weblogic dont redirect.

For Example: My jsp has a link: <a href="new">New User</a>

My controller catch the 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;
    }

This run on tomcat but when i try with weblogic he redirect to " http://localhost:7001/new " and must be " http://localhost:7001/HibernateJavaBased/new "

How can i set up the weblogic server?

UPDATE 1: my App is java config this is the initializer

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));
    }
}

And the 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;
    }

maybe on tomcat you have configured the context root. You can configure the context root in web logic as well with the file weblogic.xml If you do not have already a file weblogic.xml, make a new file weblogic.xml under /WEB-INF/ directory.

<?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> 

Hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM