JSP单选框页面跳转有问题!
点击单选框,点击提交,页面进行跳转,可是页面没反应,地址栏有反应,但是确实一些乱码,以下是我的JSP代码<%@pagelanguage="java"import="jav...
点击单选框,点击提交,页面进行跳转,可是页面没反应,地址栏有反应,但是确实一些乱码,以下是我的JSP代码
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'gztb.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<style type="text/css">
a:link {font-size:12px; text-decoration:none; color:#03515d;}
a:visited{font-size:12px; text-decoration:none; color:#03515d;}
</style>
<script language="JavaScript">
function ck(){
var gztbs = document.getElementsByName("gztb");
for (var i=0; i<gztbs.length; i++) {
alert(gztbs[i].checked);
if (gztbs[i].checked) {
alert(gztbs[i].value);
window.location.replace="gztbs["+i+"].value";
}
}
}
</script>
</head>
<body>
<form name="myform" action="" method="" onsubmit="return ck()">
<table width="100%" border="0">
<tr>
<td> <input type="radio" name="gztb" value="/njusc/admin/ribao/ribaoAdd.jsp" target='I2' />工作日报</td>
<td> <input type="radio" name="gztb" value="/njusc/admin/zhoubao/zhoubaoAdd.jsp" target='I2' />工作周报</td>
<td> <input type="radio" name="gztb" value="/njusc/admin/yuebao/yuebaoAdd.jsp" target='I2' />工作月报</td>
<td> <input type="radio" name="gztb" value="/njusc/admin/nianbao/nianbaoAdd.jsp" target='I2' />工作年报</td>
<td><input type="submit" value="提交"></td>
</tr>
</table>
</form>
</body>
</html> 展开
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'gztb.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<style type="text/css">
a:link {font-size:12px; text-decoration:none; color:#03515d;}
a:visited{font-size:12px; text-decoration:none; color:#03515d;}
</style>
<script language="JavaScript">
function ck(){
var gztbs = document.getElementsByName("gztb");
for (var i=0; i<gztbs.length; i++) {
alert(gztbs[i].checked);
if (gztbs[i].checked) {
alert(gztbs[i].value);
window.location.replace="gztbs["+i+"].value";
}
}
}
</script>
</head>
<body>
<form name="myform" action="" method="" onsubmit="return ck()">
<table width="100%" border="0">
<tr>
<td> <input type="radio" name="gztb" value="/njusc/admin/ribao/ribaoAdd.jsp" target='I2' />工作日报</td>
<td> <input type="radio" name="gztb" value="/njusc/admin/zhoubao/zhoubaoAdd.jsp" target='I2' />工作周报</td>
<td> <input type="radio" name="gztb" value="/njusc/admin/yuebao/yuebaoAdd.jsp" target='I2' />工作月报</td>
<td> <input type="radio" name="gztb" value="/njusc/admin/nianbao/nianbaoAdd.jsp" target='I2' />工作年报</td>
<td><input type="submit" value="提交"></td>
</tr>
</table>
</form>
</body>
</html> 展开
3个回答
展开全部
代码需作如下改动:
1、解决乱码问题: 把ageEncoding="UTF-8"改为ageEncoding="GBK"
2、改变提交方法: method="post"
3、改变按钮类型:<td><input type="button" value="提交" onClick="ck()"></td>
4、在第四个单选按钮下增加一隐藏域:<td> <input type="hidden" name="path" id="path" value="<%=basePath%>"/></td>
5、修改JS函数:
function ck(){
var gztbs = document.getElementsByName("gztb");
var path = document.getElementById("path");
var basePath = "";
alert(path.value);
for (var i=0; i<gztbs.length; i++) {
if (gztbs[i].checked) {
alert(gztbs[i].value);
basePath = path.value + gztbs[i].value;
alert(basePath);
window.navigate(basePath);
}
}
}
完整代码如下:
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
out.print(basePath);
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'gztb.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<style type="text/css">
a:link {font-size:12px; text-decoration:none; color:#03515d;}
a:visited{font-size:12px; text-decoration:none; color:#03515d;}
</style>
<script language="JavaScript">
function ck(){
var gztbs = document.getElementsByName("gztb");
var path = document.getElementById("path");
var basePath = "";
alert(path.value);
for (var i=0; i<gztbs.length; i++) {
if (gztbs[i].checked) {
alert(gztbs[i].value);
basePath = path.value + gztbs[i].value;
alert(basePath);
window.navigate(basePath);
}
}
}
</script>
</head>
<body>
<form name="myform" action="" method="post" onsubmit="return ck()">
<table width="100%" border="0">
<tr>
<td> <input type="radio" name="gztb" value="lisco/p43/p43101.jsp" target='I2' />工作日报</td>
<td> <input type="radio" name="gztb" value="njusc/admin/zhoubao/zhoubaoAdd.jsp" target='I2' />工作周报</td>
<td> <input type="radio" name="gztb" value="njusc/admin/yuebao/yuebaoAdd.jsp" target='I2' />工作月报</td>
<td> <input type="radio" name="gztb" value="njusc/admin/nianbao/nianbaoAdd.jsp" target='I2' />工作年报</td>
<td> <input type="hidden" name="path" id="path" value="<%=basePath%>"/></td>
<td><input type="button" value="提交" onClick="ck()"></td>
</tr>
</table>
</form>
</body>
</html>
1、解决乱码问题: 把ageEncoding="UTF-8"改为ageEncoding="GBK"
2、改变提交方法: method="post"
3、改变按钮类型:<td><input type="button" value="提交" onClick="ck()"></td>
4、在第四个单选按钮下增加一隐藏域:<td> <input type="hidden" name="path" id="path" value="<%=basePath%>"/></td>
5、修改JS函数:
function ck(){
var gztbs = document.getElementsByName("gztb");
var path = document.getElementById("path");
var basePath = "";
alert(path.value);
for (var i=0; i<gztbs.length; i++) {
if (gztbs[i].checked) {
alert(gztbs[i].value);
basePath = path.value + gztbs[i].value;
alert(basePath);
window.navigate(basePath);
}
}
}
完整代码如下:
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
out.print(basePath);
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'gztb.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<style type="text/css">
a:link {font-size:12px; text-decoration:none; color:#03515d;}
a:visited{font-size:12px; text-decoration:none; color:#03515d;}
</style>
<script language="JavaScript">
function ck(){
var gztbs = document.getElementsByName("gztb");
var path = document.getElementById("path");
var basePath = "";
alert(path.value);
for (var i=0; i<gztbs.length; i++) {
if (gztbs[i].checked) {
alert(gztbs[i].value);
basePath = path.value + gztbs[i].value;
alert(basePath);
window.navigate(basePath);
}
}
}
</script>
</head>
<body>
<form name="myform" action="" method="post" onsubmit="return ck()">
<table width="100%" border="0">
<tr>
<td> <input type="radio" name="gztb" value="lisco/p43/p43101.jsp" target='I2' />工作日报</td>
<td> <input type="radio" name="gztb" value="njusc/admin/zhoubao/zhoubaoAdd.jsp" target='I2' />工作周报</td>
<td> <input type="radio" name="gztb" value="njusc/admin/yuebao/yuebaoAdd.jsp" target='I2' />工作月报</td>
<td> <input type="radio" name="gztb" value="njusc/admin/nianbao/nianbaoAdd.jsp" target='I2' />工作年报</td>
<td> <input type="hidden" name="path" id="path" value="<%=basePath%>"/></td>
<td><input type="button" value="提交" onClick="ck()"></td>
</tr>
</table>
</form>
</body>
</html>
展开全部
因为script我不是很懂,不是很明白你的script代码。你的功能我一般都这样实现的,直接在action中写要跳转的页面,用script进行控制值的合法性!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你的action中加入你要跳转页面的地址,就是你要跳转到那个jsp页面
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询