NullPointerException,在读取HTML输入时

编程入门 行业动态 更新时间:2024-10-25 22:31:10
本文介绍了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=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.下面是完整的错误

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("\n"); //Get the List of words

此代码有什么问题?

推荐答案

使用name属性而不是id属性

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

<textarea name='wordList' value='wordList'>

阅读:表格简介

更多推荐

NullPointerException,在读取HTML输入时

本文发布于:2023-10-25 00:09:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1525383.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:NullPointerException   HTML

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!