首页 > jsp报错空指针

jsp报错空指针

学习El表达式的时候, 按照教程写了一个jsp, 但是怎么弄都报错空指针异常.
这个是jsp页面的代码

<%@ page contentType="text/html; charset=GB2312" %>
<%@ taglib prefix="mm" uri="/mytaglib" %>
<html>
<head>
<title>functions</title>
</head>

<body>



<h3>Add Numbers</h3>




<

p>


<form action="sum.jsp" method="get">
   user= <input type="text" name="user" 
        value="${mm:convert(param.user,'ISO-8859-1','GB2312')}">
   <br>
 
   x = <input type="text" name="x" value="${param.x}">
   <br>
   y = <input type="text" name="y" value="${param.y}">
   <input type="submit" value="Add Numbers">
</form>





<

p>
the sum is: ${mm:add(param.x,param.y)}

</body>
</html>

这个是taglib的代码

<taglib>
 <tlib-version>1.0</tlib-version>
 <jsp-version>1.2</jsp-version>
 <short-name>mytaglib</short-name>
 <uri>/mytaglib</uri>

 <function>
    <description>add x and y</description>
    <name>add</name>
    <function-class>hello.Tool</function-class>
    <function-signatrue>int add(java.lang.String , java.lang.String)</function-signatrue>
 </function>
 <function>
    <description>convert encoding</description>
    <name>convert</name>
    <function-class>hello.Tool</function-class>
    <function-signatrue>java.lang.String convert(java.lang.String , java.lang.String , java.lang.String)</function-signatrue>
 </function>
</taglib>

这个是taglib要连接的java代码, 一开始我以为是这个传入了空指针, 所以用if语句判断了一下, 但是还是报错

public class Tool 
{
    public static int add(String x , String y)
    {
        int a = 0 ;
        int b = 0 ;
        try
        {
            if(x==null || y==null)
            {
                x = "1" ;
                y = "2" ;
            }
            a = Integer.parseInt(x);
            b = Integer.parseInt(y) ;
        }
        catch(Exception e)
        {
            System.out.print("呵呵\n");
        }

        return a + b ;
    }

    public static String convert(String s , String encode1 , String encode2)
    {
        if(s==null || encode1==null || encode2==null)
        {
            s = "hello" ;
            encode1 = "IOS-8859-1" ;
            encode2 = "utf-8" ;
        }
        try
        {
            return new String(s.getBytes(encode1) , encode2) ;
        }
        catch(Exception e)
        {
            return null ;
        }
    }
}

这个是web.xml里面有关于taglib的配置,这个路径我查看之后也是没有错的

  <taglib>
    <taglib-uri>/mytaglib</taglib-uri>
    <taglib-location>/WEB-INF/mytaglib.tld</taglib-location>
  </taglib>

这是两个报错, 有的时候会出现第一种, 但是一按刷新按钮有可能就出现第二种了


找了20多分钟了,还是不知道哪里错了


看图是少了相应的class。说明少了El方面的jar包。


看看是不是jsp-api的jar包重复了。tomcat的lib是不是也有一个。

【热门文章】
【热门文章】