You are creating a Web application for booking hotel rooms online. You are using Spring to create this application. When a user accesses the BookRoom.htm Web page of this application, the dispatcher servlet needs to forward the request for accessing this Web page to the BookRoomController class defined in the controller package. For this, you need to map the URL, /BookRoom.htm, with the BookRoomController class. Which of the following code snippets should you use to implement this functionality?
时间: 2024-03-21 21:43:00 浏览: 18
To map the URL `/BookRoom.htm` with the `BookRoomController` class, you should use the `@RequestMapping` annotation in the controller class. Here is an example of how to do this:
```java
@Controller
public class BookRoomController {
@RequestMapping(value = "/BookRoom.htm", method = RequestMethod.GET)
public ModelAndView showBookRoomPage() {
// code to show the BookRoom page
return new ModelAndView("bookRoomPage");
}
// other methods for handling form submissions, etc.
}
```
In this example, the `@RequestMapping` annotation is used to map the URL `/BookRoom.htm` to the `showBookRoomPage()` method of the `BookRoomController` class. The `method` attribute specifies that this mapping is for HTTP GET requests only. The method returns a `ModelAndView` object that specifies the view name (`bookRoomPage`) to be rendered by the dispatcher servlet.