java - Issue with spring error-page and web.xml -


here web.xml:

<error-page>     <error-code>404</error-code>     <location>/error/404</location> </error-page> 

below controller class :

import org.springframework.stereotype.controller; import org.springframework.ui.modelmap; import org.springframework.web.bind.annotation.requestmapping; import org.springframework.web.servlet.modelandview; import javax.servlet.http.httpservletrequest;   @requestmapping(value = "/error") @controller public class errorcontroller {  @requestmapping(value = {"/307", "/400", "/401", "/403", "/404", "/405", "500", "503"}) public modelandview error(httpservletrequest request) throws exception {     string path = request.getservletpath().replace("/error/", "");     return new modelandview("redirect:/error/view/"+path); } 

if request error url this

http://localhost:8080/erro/ 

it display 404 error-page change url

http://localhost:8080/error/view/404 

if invalid url requested, error page appears old url has changed. need fix old url not change , error page appears?

thanks :)

in case need use forward: instead of redirect:

redirect working on client side sending location header browser, that's why url changing.

forward working on server side choosing file send response browser.

but be careful forward, because lead security issue if use user-controlled input. in case attacker able to download file war (it depends on configuration in extremely cases able download compiled java classes).


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -