『壹』 jsp中的 if else if语句
else if(username=="管理员");{
改为
else if(username=="管理员"){
多个;证明else if结束了,而后面跟代码没有问题,但最后的else找不到对应的if,所以报错
『贰』 jsp中 的if else 怎么对啊
问题出在了这一句:
if (password1 == password2)
原因分析:
1)String password1和password2直接比较是在判断其在内存中的引用(地址位置),所以如果想要两个非基础类型变量相等需要有以下条件:
String pw1 = new String();
String pw2 = pw1; // 现在pw1 == pw2,可以参考 jse docs java.lang.object.equals()
2)如果想进行两个非基础类型变量进行其value的比较,需要实现以下方法:
public boolean Object.equals(Object obj);
jse docs中的描述是(英文,要是嫌烦可以先跳到中文。这里简单描述了该方法具有自反
性、对称性、传递性。其实可以联想数学概念理解其含义):
Indicates whether some other object is "equal to" this one.
The equals method implements an equivalence relation on non-null object references:
It is reflexive: for any non-null reference value x, x.equals(x) should return true.
It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
For any non-null reference value x, x.equals(null) should return false.
The equals method for class Object implements the most discriminating possible equivalence relation on objects; that is, for any non-null reference values x and y, this method returns true if and only if x and y refer to the same object (x == y has the value true).
Note that it is generally necessary to override the hashCode method whenever this method is overridden, so as to maintain the general contract for the hashCode method, which states that equal objects must have equal hash codes.
也就是说,Object间进行values是否相等的判断需要使用equals(Object obj)方法,
String.equals(Object obj)已经为JSE overwrite。所以你在此进行相等判断应该使用如下方法:
if ( pw1.equals ( pw2 ) ) { } ; // 参见 jse docs java.lang.String
3)如果需要实现对象间的比较(大小、相等),除了要重写equals()方法外,还要实现Comparable<T>接口,并实现其中的int compareTo(T obj)方法。具体请参见jse docs中的Comparable.compareTo(T o)描述。比如可以进行比较的Date等都是实现了该接口,如果你设计的Type类型实现进行排序等要求,毋庸置疑也需要实现该接口及该方法。
『叁』 jsp中如何用jstl实现if(){}else if(){}else{}这种形式的判断
具体做法是:
<c:choose>
<c:when test="${条件}">
情况1:
</c:when>
<c:when test="${条件}">
情况2:
</c:when>
<c:otherwise>
否则。。。。。
</c:otherwise>
</c:choose>
所以实现了内这种形式的判断。
『肆』 如何在JSP页面中实现 使用 C:TAG 判断 if。 else if。else
你语法错了,改成如下:checked="checked"/>男checked="checked"/>女其实我自己也经常犯这种细节错误,呵呵。