jsp文件执行出错(50分)

  • 主题发起人 主题发起人 jerjoan
  • 开始时间 开始时间
J

jerjoan

Unregistered / Unconfirmed
GUEST, unregistred user!
example3a.jsp 文件内容如下:
<!--http://localhost/example3a.jsp?bal=222.45&amp;fName=Steven-->
<html>
<head><title>Sessino Example</head></title>
<body>
<p>
<h1>Where wil your balance take you?</h1>
<br>
<%--Get paramaters for the request object--%>
<%String firstName = request.getParameter("fName");%>
<%String balance = request.getParameter("bal");%>
<%--Convert the bal paramater from String todo
uble--%>
<%double accountBalance =do
uble.valueOf(balance).doubleValue();%>
<%--Write the input paramaters to the Session object. The Session object cannot store ado
uble,You must first convert it to do
uble.--%>
<%
Session.setAttribute("userName",firstName);
do
uble tempAccountBalance = newdo
uble(accountBalance);
Session.setAttribute("userBalance",tempAccountBalance);
%>
<%--Output result--%>
Balance for<%= firstName%>:<% = accountBalance%><br>
<br><br>
Do you need a <a href = "example3b.jsp">invest your money</a>?
<br><br>
Do you need a <a href = "example3c.jsp">job</a>.
</body>
</html>
我编译后出现如下错误:(我采用的是jdk1.4+Tomcat4.0,已完成配置,一些简单的jsp文件可以正常执行)
org.apache.jasper.JasperException: Unable to compile class for JSPNote: sun.tools.javac.Main has been deprecated.
../work/localhost/mysite/_0002fexample_00033a_0002ejspexample3a_jsp_0.java:103: Missing term.
out.write(":");
是文件有错,还是有什么没有完成的配置.
 
你把work里对应的servlet打开看看,也许能找到错误
 
我想问题是在:
Balance for<%= firstName%>:[red]<% = accountBalance%>[/red]<br>
应当是]<%=accountBalance%>
<% 和 = 之间的那个空格要去掉
 
hi, mor
我按你说的做了,可是没有效果.
 
hi,mor
不好意思,我按你说的做后虽然还有错,可是错误不一样了帮忙看一下吧.
 
以下是新的报错
org.apache.jasper.JasperException: Unable to compile class for JSPNote: sun.tools.javac.Main has been deprecated.
../work/localhost/mysite/_0002fexample_00033a_0002ejspexample3a_jsp_0.java:87: Undefined variable or class name: Session
Session.setAttribute("userName",firstName);
^
../work/localhost/mysite/_0002fexample_00033a_0002ejspexample3a_jsp_0.java:89: Undefined variable or class name: Session
Session.setAttribute("userBalance",tempAccountBalance);
 
在线等待,望高手指教.
 
Session应该是session
jerjoan你是刚学jsp吧,我一开始转到java时也是这样的,不要着急不要灰心,想当初我写jsp的时候也是刷~~~~~~~~的一下报上数百个错的[:(]
 
谢谢你,mor,你说得没错,我是新手,可这jsp也太折磨人了,你瞧,改完了session 又有下面这么多错,
A Servlet Exception Has Occurred
Exception Report:
javax.servlet.ServletException
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:481)
at _0002fexample_00033a_0002ejspexample3a_jsp_0._jspService(_0002fexample_00033a_0002ejspexample3a_jsp_0.java:117)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:184)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:328)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:407)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:251)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:977)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:196)
at org.apache.catalina.valves.ValveBase.invokeNext(ValveBase.java:242)
at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:242)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:975)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2041)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
at org.apache.catalina.valves.ValveBase.invokeNext(ValveBase.java:242)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:414)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:975)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:159)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:977)
at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:818)
at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:897)
at java.lang.Thread.run(Thread.java:536)
Root Cause:
java.lang.NullPointerException
at java.lang.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:983)
at java.lang.Double.valueOf(Double.java:184)
at _0002fexample_00033a_0002ejspexample3a_jsp_0._jspService(_0002fexample_00033a_0002ejspexample3a_jsp_0.java:75)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:184)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:328)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:407)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:251)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:977)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:196)
at org.apache.catalina.valves.ValveBase.invokeNext(ValveBase.java:242)
at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:242)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:975)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2041)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
at org.apache.catalina.valves.ValveBase.invokeNext(ValveBase.java:242)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:414)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:975)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:159)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:977)
at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:818)
at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:897)
at java.lang.Thread.run(Thread.java:536)
无论如何请指点一下.
 
我做了一个最简单的html表单提交页面
<html>
<body>
<form method=post action="example3a.jsp">
<input type="text" name="fName">
<input type="text" name="bal">
<input type="submit">
</form>
</form>
</body>
</html>
然后执行,没有任何问题
 
谢谢你,mor,是我后来执行的时候忘了带参数了,奉上50.不知能否留个QQ.我还有很多问题想像你请教.不过如果不方便,也没关系.
 
帮你分析一下:
你的jsp程序应当是由另一个页面调用的,比如我上面的那个test.html,其中一个表单提交两个参数:fName和bal,提交给example3a.jsp后,jsp从request中用getParameter()方法得到这两个参数。over。
现在再看报错的信息,Root Cause是java.lang.NullPointerException,这是一个空指针报错,这种错误是最麻烦的,不过好在这个jsp不太复杂,往下看
at java.lang.Double.valueOf(Double.java:184)
原来是在调用Double.valueOf()时出错了,找到使用这个方法的地方:
<%double accountBalance =do
uble.valueOf(balance).doubleValue();%>
很显然,这里只有一个对象,就是balance,它是null(你可以加一行<%= balance%>把它输出看看),而balance在那里被赋值的呢?在这里:
<%String balance = request.getParameter("bal");%>
所以唯一的可能就是request里没有bal这个参数,我把test.html里<input type="text" name="bal">改成<input type="text" name="balance">,再刷新一下,bingle!!和你上面报的错一样。
做java都是这样的,要学会从报的错中找到问题来,慢慢来吧

 
QQ:76215324,不过不常上,最近比较忙。
有事可以发mail给我,char_mor@citiz.net,我会尽快回复的
 

Similar threads

Z
回复
7
查看
295
zhang12321
Z
X
回复
5
查看
377
xiaotianwangzi
X
回复
15
查看
286
向你学习
后退
顶部