tomcat实现不带项目名称访问项目
当通过浏览器访问tomcat时,如果只有ip+端口而没有项目名称,则访问的是webapps/ROOT/index.html,
修改Tomcat的webapps/ROOT/index.html自动跳转到指定url即可
自动跳转到指定页面,不改变URL
实现代码
<!DOCTYPE html>
<html lang="cn">
<head>
<title>demo</title>
<script>
function createXMLHttpRequest() {
if (window.XMLHttpRequest) {
XMLHttpR = new XMLHttpRequest();
} else if (window.ActiveXObject) {
try {
XMLHttpR = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
XMLHttpR = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
}
}
}
}
function sendRequest(url) {
createXMLHttpRequest();
XMLHttpR.open("GET", url, true);
XMLHttpR.setRequestHeader("Content-Type", "text/html;charset=utf-8");
XMLHttpR.onreadystatechange = processResponse;
XMLHttpR.send(null);
}
function processResponse() {
if (XMLHttpR.readyState == 4 && XMLHttpR.status == 200) {
document.write(XMLHttpR.responseText);
}
}
//项目的名称和首页html
sendRequest("/app/index.html");
</script>
</head>
<body>
</body>
</html>
说明:核心实现参考自互联网
问题
如果直接跳转到http开头的地址,则会有跨域问题
(全文完)
欢迎光临:松果前端开发导航