jsp中字符串相等的判断
<%@pagecontentType="text/html;charset=gb2312"language="java"import="java.sql.*"errorP...
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<script>
function sbmt(name){
if (name=="b1"){
document.f1.t.value="1";
f1.submit();
}
else if(name=="b2"){
document.f1.t.value="2";
f1.submit();
}
}
</script>
<form id="f1" name="f1" method="post" action="">
<label></label>
<label>
<input type="submit" name="b1" value="forward1" onclick="sbmt('b1');" />
</label>
<label>
<input type="submit" name="b2" value="forward2" onclick="sbmt('b2');" />
</label>
</p>
<label>
<input type="hidden" name="t" value="0" />
</label>
</form>
<%
String a=request.getParameter("t");
out.println(a);
if(a=="0"){
out.print("000");
out.print("111");
}
else
{
if(a=="1"){
%>
<jsp:forward page="forward1.jsp">
<jsp:param name="f" value="forward1" />
</jsp:forward>
<%
}
else if(a=="2"){
%>
<jsp:forward page="forward2.jsp">
<jsp:param name="f" value="forward2" />
</jsp:forward>
<%
}
}
out.println("aaaaaaaaaaaa");
out.println(a);
%>
</body>
</html>
运行面时
点击b1 按钮 输出a的值为1,点击按钮b2时输出a的值为2,可是if(a=="1")和if(a=="2")里面都没执行到,不知道哪里出问题?字符串相等的判断应该没错。。请大家帮帮忙咯~~在此谢谢了。。
用equals或compareTo都不行咯,出现如下错误:
org.apache.jasper.JasperException: An exception occurred processing JSP page /forward.jsp at line 39
36: <%
37: String a=request.getParameter("t");
38: out.println(a);
39: if(a.equals("0")){
40: out.print("000");
41: out.print("111");
42: } 展开
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<script>
function sbmt(name){
if (name=="b1"){
document.f1.t.value="1";
f1.submit();
}
else if(name=="b2"){
document.f1.t.value="2";
f1.submit();
}
}
</script>
<form id="f1" name="f1" method="post" action="">
<label></label>
<label>
<input type="submit" name="b1" value="forward1" onclick="sbmt('b1');" />
</label>
<label>
<input type="submit" name="b2" value="forward2" onclick="sbmt('b2');" />
</label>
</p>
<label>
<input type="hidden" name="t" value="0" />
</label>
</form>
<%
String a=request.getParameter("t");
out.println(a);
if(a=="0"){
out.print("000");
out.print("111");
}
else
{
if(a=="1"){
%>
<jsp:forward page="forward1.jsp">
<jsp:param name="f" value="forward1" />
</jsp:forward>
<%
}
else if(a=="2"){
%>
<jsp:forward page="forward2.jsp">
<jsp:param name="f" value="forward2" />
</jsp:forward>
<%
}
}
out.println("aaaaaaaaaaaa");
out.println(a);
%>
</body>
</html>
运行面时
点击b1 按钮 输出a的值为1,点击按钮b2时输出a的值为2,可是if(a=="1")和if(a=="2")里面都没执行到,不知道哪里出问题?字符串相等的判断应该没错。。请大家帮帮忙咯~~在此谢谢了。。
用equals或compareTo都不行咯,出现如下错误:
org.apache.jasper.JasperException: An exception occurred processing JSP page /forward.jsp at line 39
36: <%
37: String a=request.getParameter("t");
38: out.println(a);
39: if(a.equals("0")){
40: out.print("000");
41: out.print("111");
42: } 展开
6个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询