Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsp NullPointerException,在读取HTML输入时_Jsp_Servlets_Nullpointerexception - Fatal编程技术网

Jsp NullPointerException,在读取HTML输入时

Jsp NullPointerException,在读取HTML输入时,jsp,servlets,nullpointerexception,Jsp,Servlets,Nullpointerexception,这是我的密码: JSP页面 <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title&g

这是我的密码:

JSP页面

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h1><center>Web Site Analizer</center></h1>
        <br/>
        <form action=http://localhost:8080/WebSiteAnalizer/SiteAnalizer method=post>
            Enter the Percentage (0-100): <input type="Text" id="percentage">
            <br/><br/><br/>

            Enter the Words (Separated from New Line (/n)): <br/>
            <textarea id='wordList' value='wordList'></textarea>            
            <br/><br/>

            <input type="submit" value="Submit">

        </form>
    </body>
</html>
当我运行这个应用程序时,我得到了
NullPointerException
。下面是全部错误

java.lang.NullPointerException
    SiteAnalizer.doPost(SiteAnalizer.java:40)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
第40行是

String[] listOfWords = request.getParameter("wordList").toLowerCase().trim().split("\n"); //Get the List of words

此代码有什么问题?

使用
name
属性而不是
id
属性

<input type="Text" name="percentage">



阅读:

要能够将其作为参数访问,应将“wordList”指定为“name”,而不是值:

<textarea id='wordList' name='wordList'></textarea>  


另外,在代码的其余部分使用该字段之前,请确保验证该字段以检查其是否为空。

我认为您需要指定名称attr:

谢谢您的回复+谢谢你的回复+1 from me:)元素的
id
属性由类似JavaScript的客户端脚本引用。
name
属性作为请求参数提供。因此,它们在服务器上可用。
<textarea name='wordList' value='wordList'>
<textarea id='wordList' name='wordList'></textarea>