我開發了一個簡單的jsp頁面,其中包含兩個文本字段和一個提交按鈕以添加兩個數字。在瀏覽器編譯後,它顯示了一個錯誤:jsp頁面中的數字格式異常
HTTP Status 500
org.apache.jasper.JasperException: java.lang.NumberFormatException: null
下面的代碼:
所有的 <%--
Document : index
Created on : Mar 5, 2013, 7:21:57 PM
Author : VIJI
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<form>
<input type="text" name="a"></input>
<input type="text" name="b"></input>
<input type="submit" value="ADD"></input>
<%!
int a,b,c;
%>
<%
a=Integer.parseInt(request.getParameter("a"));
b=Integer.parseInt(request.getParameter("b"));
c=a+b;
%>
Addition of two numbers is<%=c%>
</form>
</body>
[使用的JSP腳本小程序(這些'<% %>'東西),因爲標籤庫(如JSTL)和EL(表達式語言,那些'$ {}'的東西)的十年前誕生的強烈勸阻。 **在新代碼中避免scriptlets。**](http://stackoverflow.com/q/3177733/139010) – 2013-03-05 14:06:11