Can SpringMVC pick up all unmapped requests?
For example,
@RequestMapping(value="/{otherwise:.+}", method=RequestMethod.GET)
public String otherwise() threads Exception {
US>throw new TargetNotFoundException("The specified page could not be found.");
}
@ExceptionHandler (TargetNotFoundException.class)
@ResponseStatus (value=HttpStatus.OK)
public String HandleException (final TargetNotFoundExceptione,
HttpServletRequest request,
HttpServletResponse response) {
LOGGER.error(e.getMessage());
e.printStackTrace();
request.setAttribute("message", e.getMessage());
request.setAttribute("status", "404");
return "error";
}
If so,
http://domain/{.+} unmapped requests can be controlled, but
The http://domain/{.+}/{.+} URL is processed in the servlet container.
I'm trying to do something that I can't handle by error code on web.xml, so I'd like to pick it up with the controller.
Also, I thought about how to redirect at the transport layer, but it's troublesome to think that I have to set it up for each web application, so if I can handle it at the application layer, that's better.
@RequestMapping value is multiplied by an ant pattern, so
If you don't use PathVariable, I think /**
is fine.
However, for all http://domain/ContextRoot/**
, JavaScript, CSS, etc.
I can't solve it well.
For example,
@RequestMapping("/**")
@Cotroller
public class SomeController {
@RequestMapping(value="/**")
public String index() {
return "index";
}
}
/js/some.js
and /css/style.css
are also handled by the controller.
613 GDB gets version error when attempting to debug with the Presense SDK (IDE)
582 PHP ssh2_scp_send fails to send files as intended
620 Uncaught (inpromise) Error on Electron: An object could not be cloned
916 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
© 2024 OneMinuteCode. All rights reserved.