的時候,這裏是我的代碼: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("\n"); //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
,當我運行該應用程序。下面是完整的錯誤
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
什麼是錯的代碼?
元素的'id'屬性由像JavaScript客戶端腳本中引用。 name屬性作爲請求參數提供。因此,它們在服務器上可用。 – Tiny