主题:今天刚遇到的编译问题,大家都来看看
源程序1(名字为:client.html):
<!--客户端和服务器的程序 假如在客户端输入一个整数,要求在服务器端计算该整数加1的值,服务器并把结果返回给客户端显示出来;如果是字符串的话,服务器端的程序就直接把结果返回给客户端并显示出来。-->
<html>
<head>
<title>a simple example</title>
</head>
<body>
<h2>客户端</h2><br>
<form name="fm" action="transform.jsp" method="post">
<p>输入你所要的值:
<input type="text" name="inputvalue">
<input type="submit" value="提交"></p>
</form>
</body>
</html>
源程序2(名字为transform.jsp):
<%@page import="java.io.*"%>
<%
try{
String inputvalue = request.getParameter("inputvalue");
String outputvalue="";
int str_length = inputvalue.length();
int i = 1;
int flag = 1;
int integerNum = 0;
//校验输入值
if(!inputvalue.equals(""))
{
while(i <= str_length && flag ==1)
{
if(inputvalue.charAt(i)>'9' || inputvalue.charAt(i)<'0') flag = 0;
if(flag == 1) {
integerNum = Integer.parseInt(inputvalue) + 1;
outputvalue = Integer.toString(integerNum);
}
else outputvalue = inputvalue;
i++;
}
}
else{
%>
输入值为空!
<a href="client.html">请点击这里重新输入</a>
<%
}
%>
<html>
<%@ page contentType="text/html;charset=gb2312" %>
<body>
<title>Answer</title>
<h2>服务器返回给客户端的值</h2>
输出值:<%=outputvalue%>
</body>
</html>
<%
}
catch(NumberFormatException e)
{
%>
<a href="client.html">请点击这里重新输入</a>
<%
}
%>
3.错误报告如下:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: String index out of range: 2
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:372)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
java.lang.StringIndexOutOfBoundsException: String index out of range: 2
java.lang.String.charAt(String.java:444)
org.apache.jsp.transform_jsp._jspService(transform_jsp.java:59)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.
--------------------------------------------------------------------------------
Apache Tomcat/5.0.28
<!--客户端和服务器的程序 假如在客户端输入一个整数,要求在服务器端计算该整数加1的值,服务器并把结果返回给客户端显示出来;如果是字符串的话,服务器端的程序就直接把结果返回给客户端并显示出来。-->
<html>
<head>
<title>a simple example</title>
</head>
<body>
<h2>客户端</h2><br>
<form name="fm" action="transform.jsp" method="post">
<p>输入你所要的值:
<input type="text" name="inputvalue">
<input type="submit" value="提交"></p>
</form>
</body>
</html>
源程序2(名字为transform.jsp):
<%@page import="java.io.*"%>
<%
try{
String inputvalue = request.getParameter("inputvalue");
String outputvalue="";
int str_length = inputvalue.length();
int i = 1;
int flag = 1;
int integerNum = 0;
//校验输入值
if(!inputvalue.equals(""))
{
while(i <= str_length && flag ==1)
{
if(inputvalue.charAt(i)>'9' || inputvalue.charAt(i)<'0') flag = 0;
if(flag == 1) {
integerNum = Integer.parseInt(inputvalue) + 1;
outputvalue = Integer.toString(integerNum);
}
else outputvalue = inputvalue;
i++;
}
}
else{
%>
输入值为空!
<a href="client.html">请点击这里重新输入</a>
<%
}
%>
<html>
<%@ page contentType="text/html;charset=gb2312" %>
<body>
<title>Answer</title>
<h2>服务器返回给客户端的值</h2>
输出值:<%=outputvalue%>
</body>
</html>
<%
}
catch(NumberFormatException e)
{
%>
<a href="client.html">请点击这里重新输入</a>
<%
}
%>
3.错误报告如下:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: String index out of range: 2
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:372)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
java.lang.StringIndexOutOfBoundsException: String index out of range: 2
java.lang.String.charAt(String.java:444)
org.apache.jsp.transform_jsp._jspService(transform_jsp.java:59)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.
--------------------------------------------------------------------------------
Apache Tomcat/5.0.28