当前位置: 代码迷 >> Java Web开发 >> 请问:javabean的一个奇怪的异常
  详细解决方案

请问:javabean的一个奇怪的异常

热度:703   发布时间:2016-04-17 13:03:35.0
请教:javabean的一个奇怪的错误
test1.jsp
<%@   page   language= "java "   contentType= "text/html;   charset=GB2312 "
        pageEncoding= "GB2312 "%>
<html>
<head>
    <title> test </title>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=GB2312 ">
</head>
<body>
<form   name= "form1 "   action= "test2.jsp "   method= "post "     >
    <p> 姓名:
        <input   type= "text "   name= "name ">
    </p>
    <p>  
        <input   type= "submit "   value= "传送 ">
        <input   type= "reset "   value= "取消 ">
    </p>
</form>
</body>
</html>


test2.jsp
<%@   page   contentType= "text/html;charset=GB2312 "   %>
<%@   taglib   prefix= "fmt "   uri= "http://java.sun.com/jsp/jstl/fmt "   %>
<html>
<head>
    <title> CH8   -   Introspection.jsp </title>
</head>
<body>
<fmt:requestEncoding   value= "GB2312 "   />
<jsp:useBean   id= "myBean "   scope= "page "   class= "bamboo.SimpleBean "/>
<jsp:setProperty   name= "myBean "   property= "* "   />
<%String   qq=myBean.searchrs();  
out.println(qq);%>
</body>
</html>


SimpleBean.java
package   bamboo;
import   java.io.*;
public   class   SimpleBean{
    public   SimpleBean()   {
    }

    private   String   name;

    public   void   setName(String   name)   {
        this.name   =   name;
    }
   
    public   String   getName()   {
        return   name;
    }
   

    public   String   searchrs()throws   Exception{  
    String   qq= "www ";
    if(!name.equals( " ")   &&   name!=null){
    qq= "hello   world! ";
    }
    return   qq;
    }
    }

在test1.jsp的输入框中输入任何字后点击 "传送 ",显示 "hello   world! ",而如果test1.jsp的输入框中不输入任何字就点击 "传送 ",结果并不是显示 "www ",而是显示有错,提示错误在SimpleBean.java的判断语句,请大家帮忙看一下这个判断语句哪里有错,谢谢!
if(!name.equals( " ")   &&   name!=null){
    qq= "hello   world! ";
    }


------解决方案--------------------
if(name!=null&& !name.equals( " ") ){
qq= "hello world! ";
}


------解决方案--------------------
if(name != null){
qq= "hello world! ";
}
  相关解决方案