Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mapping jsp for a url in Spring 3 without using controller

How to map a jsp for a url in spring 3 without requestmapping to any controller.

eg. /login to login.jsp without having any userdefined controller in between

Like URLFILENAMECONTROLLER in spring2.5, similarly in spring 3

like image 765
user1611575 Avatar asked Dec 01 '22 21:12

user1611575


2 Answers

You can use this paragraph from Spring docs for reference. In short, you can do in several ways one of them with view-controller annotation. The other way when using Java Config:

@EnableWebMvc
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {

  @Override
  public void addViewControllers(ViewControllerRegistry registry) {
    registry.addViewController("/login").setViewName("login");
  }

}

Where the code maps request for /login to /WEB-INF/views/login.jsp view if the view resolver is defined as in the previous answer.

like image 146
Oleksandr Bondarenko Avatar answered Dec 15 '22 01:12

Oleksandr Bondarenko


You can do this:

<mvc:view-controller path="/login" view-name="login"/>

Assuming that you have defined a ViewResolver, something like this:

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/views/" />
    <property name="suffix" value=".jsp" />
</bean>

This will resolve a request to /login to a /WEB-INF/views/login.jsp page

like image 23
Biju Kunjummen Avatar answered Dec 15 '22 01:12

Biju Kunjummen