一个简易的程序,建两个html,每个里面都有一个按钮,我想点击第一个页面的按钮,跳转到第二个,再点击第二个页面的按钮,跳回来,和登陆之后,跳转到当前页面的原理一样,求java程序应该怎么写
Java是服务器端语言,实现这个功能你需要的是javascript。
首先创建两个空文件a.html和b.html,保存在同一个目录下。
之后写入代码如下:
a.html
<html>
<head>
<title>Page A</title>
<script type="text/javascript">
function redirect() {
window.location.href='b.html'
}
</script>
</head>
<body>
<h1>This is page A.</h1>
<br/>
<button title="Go to page B" onclick="javascript:redirect()">Go to page B</button>
</body>
</html>
b.html
<html>
<head>
<title>Page B</title>
<script type="text/javascript">
function redirect() {
window.location.href='a.html'
}
</script>
</head>
<body>
<h1>This is page B.</h1>
<br/>
<button title="Go to page A" onclick="javascript:redirect()">Go to page A</button>
</body>
</html>
注意在IE中运行的时候要允许浏览器执行script。
如果不希望浏览器保存回退历史,可以用window.location.replace('b.html');
直接在body里写标签写要写的内容就行
你问的是java里面怎么写是吧?
用servlet跳转
点击a.html中的按钮调用js事件通过servlet跳转到b.html
request.getRequestDispatcher("a.html").forward(request, response);
点击b.html中的按钮通过servlet跳转到a.html
request.getRequestDispatcher("b.html").forward(request, response);