NullPointerException,读取 HTML 输入时 [英] NullPointerException, when reading HTML input
本文介绍了NullPointerException,读取 HTML 输入时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码:
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>
Servlet
public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException
{
String[] listOfWords = request.getParameter("wordList").toLowerCase().trim().split("
"); //Get the List of words
int percentage = Integer.parseInt(request.getParameter("percentage")); // Get the percentage value
int numberOfWordsInProgramHash = 0; //Keep tracks of how many words in "program" per webpage
int primaryKey = 0; //Store the primary key
}
当我运行这个应用程序时,我得到了 NullPointerException
.以下是完整错误
I get the NullPointerException
, when I run this application. Below is the full error
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("
"); //Get the List of words
这段代码有什么问题?
推荐答案
使用 name
属性代替 id
属性
Use the name
attribute instead of the id
attribute
<input type="Text" name="percentage">
和
<textarea name='wordList' value='wordList'>
阅读:表单简介
这篇关于NullPointerException,读取 HTML 输入时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文