我正在前端使用 React 创建 Spring Boot 应用程序。我可以在浏览器中打开该页面,但在后端出现错误:
RequestRejectedException: The request was rejected because the URL contained a potentially malicious String "//"
所以我有一个简单的 java-view 控制器:
@Controller
public class ViewController {
@RequestMapping("/")
public String index() {
return "index";
}
}
它返回 html:
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8" http-equiv="CONTENT-TYPE" content="text/html; charset=UTF-8"/>
<title>Hello demo</title>
<link href="/build/react_app.css" rel="stylesheet"></head>
<body>
<div id="react"></div>
<script src="/build/js/main.min.js"></script><script src="/build/js/react_app.min.js"></script></body>
</html>
所以在反应应用程序中我连接了反应路由器,这是我的index.js:
const middleware = [thunk, createLogger()];
let container = document.getElementById('react');
const store = createStore(
reducer,
compose(applyMiddleware(...middleware))
);
ReactDOM.render(
<Provider store={store}>
<Router history={hashHistory}>
<Switch>
<Route exact path="/" component={MainPage}/>
<Route exact path="/login" component={LoginPage}/>
<Route exact path="/registration" component={RegistryPage}/>
<Route path="*" component={NotFound}/>
</Switch>
</Router>
</Provider>,
container
);
export default store;
所以基本上我可以访问主页,它呈现正常。我可以在路线之间切换,但同时在后端我看到错误。我调试并意识到为什么会发生这种情况。主页的网址是
http://localhost:8080/#/
如果我使用网址http://localhost:8080/#
没关系,没有例外。我怎样才能解决这个问题?如果我删除这些斜线之一就无法正常工作