在test.jsp中加载computer3.jsp,将1.jsp中的form文本框中的值传给computer3总是出现nullpointexception不知为何,请各位帮忙
<!--test.jsp>
<%@page contentType="text/html;charset=GBK" %>
<%@page import="java.lang.*" %><html>
<head><title>静态加载页面
</title>
</head>
<body>
这是一个静态
<form method="get" name="form" action="Computer3.jsp">
accomulate the sqrs:
<input type="text" name="text1"value="">
<input type="submit" name="sub" value="submit">
</form>
<%@include file="Computer3.jsp" %>
</body>
</html>
<%@ page language="java" %>
<%@ page import="java.lang.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
异常捕获也是出现 :error<title>static </title>
</head>
<body><%
String str;
try{
double a=0;
str=request.getParameter("text1");
if(str==null){
str="";
}
a=Double.parseDouble(str);
double b=0;
b=Math.sqrt(a);
out.println(String.valueOf(a)+" 's sqrt is"+String.valueOf(b));
}
catch(Exception e){
out.println("error");
}%>
</body>
</html>
<!--test.jsp>
<%@page contentType="text/html;charset=GBK" %>
<%@page import="java.lang.*" %><html>
<head><title>静态加载页面
</title>
</head>
<body>
这是一个静态
<form method="get" name="form" action="Computer3.jsp">
accomulate the sqrs:
<input type="text" name="text1"value="">
<input type="submit" name="sub" value="submit">
</form>
<%@include file="Computer3.jsp" %>
</body>
</html>
<%@ page language="java" %>
<%@ page import="java.lang.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
异常捕获也是出现 :error<title>static </title>
</head>
<body><%
String str;
try{
double a=0;
str=request.getParameter("text1");
if(str==null){
str="";
}
a=Double.parseDouble(str);
double b=0;
b=Math.sqrt(a);
out.println(String.valueOf(a)+" 's sqrt is"+String.valueOf(b));
}
catch(Exception e){
out.println("error");
}%>
</body>
</html>
解决方案 »
- Weblogic求教,大神们快来
- 关于Spring中使用Quartz的问题?
- 昨天还好好的,今天突然报404错误The requested resource (/framework/) is not available
- 怎么将null转换为BigDecimal类型
- Freemarker读取session 及判断语句的问题
- org.hibernate.util.JDBCExceptionReporter - SQL Error: 2289, SQLState: 42000
- 请问JAVA虚拟机的源代码哪里有下载?
- 用log4j在mysql下为什么插入的中文数据是乱码
- 如何使用Apache的HSSF(POI)来写上万行的Excel报表
- 大家来看一下网易的网络通行证是怎么用ejb实现的
- Spring2.5 @Resource引入的bean为什么为空呢
- jsp 分页显示 出现下面错误,哪位大侠给看看
去掉,看看
那么在你访问这个页面的时候,他的加载是把test.jsp和Computer3.jsp全部读取出来在一起编译成一个页面显示,这个过程里面没有请求 request 那你用request.getParameter就取不到任何东西。你要想取得话很简单用dom就可以了 document.getElementById()
try{
double a=0;
str=request.getParameter("text1");
if(str==null){
str=""; //改成str="88888888";}
a=Double.parseDouble(str);如果str=null,str=""以及str不是纯数字,这句话都会出现异常。调试思路:按照蓝色部分。根因:看起来你是想把请求由A转发到B,而A又包含了B。麻烦你直接把A的action指向A自己。把B的那块代码写到A里面去。jsp包含虽然很方便,但是使用不当带来的负面问题也很多
if(str==null){
str="";
}这样就行,但对于我的这段代码不起作用,我也知道这是空指针异常,就是不知如何修改,上面的一位仁兄也说了让第二段代码加到第一个页面,关键是我想在两个页面中处理请求,这可如何是好啊,请各位大侠指教!