qqwer5655111 2015-11-19 09:01 采纳率: 0%
浏览 1646

jsp中response实验,为什么出不了结果

inputnumber.jsp

 <%@ page contentType="text/html;charset=utf-8" %>
<%@ taglib tagdir="/WEB-INF/tags" prefix="computer"%> 
<html>
    <body bgcolor="blanchedalmond">
        <font size="3">
            <form action="" method="post" name="form" >
            输入运算数,选择运算符号:
            <br><input type="text" name="numberone" size="6" />
            <select name="operator">
                <option value="+">+
                <option value="-">-
                <option value="*">*
                <option value="/">/
            </select>
            <input type="text" name="numbertwo" size="6" />
            <br><input type="submit" value="提交你的选择" name="submit" />
            </form>
            <%
                String a=request.getParameter("numberone");
                String b=request.getParameter("numbertwo");
                String operator=request.getParameter("operator");
                if(a==null||b==null){
                    a="";
                    b="";
                }
                if(a.length()>0&&b.length()>0){
            %><computer:computer numberA="<%=a%>" numberB="<%=b%>" operator="<%=operator%>" />
            计算结果是:<%=a%><%=operator%><%=b%>=<%=result%>
                <%}%>
        </font>
    </body>
</html>

computer.tag

 <%@ tag pageEncoding="utf-8" %>
<%@ attribute name="numberA" required="true" %>
<%@ attribute name="numberB" required="true" %>
<%@ attribute name="operator" required="true" %>
<%@ variable name-given="result" scope="AT-END" %>
<% try{
    double a=Double.parseDouble(numberA);
    double b=Double.parseDouble(numberB);
    double r=0;
    if(operator.equals("+"))
    r=a+b;
    else if(operator.equals("-"))
    r=a-b;
    else if(operator.equals("*"))
    r=a*b;
    else if(operator.equals("/"))
    r=a/b;
    jspContext.setAttribute("result",String.valueOf(r));
    }
    catch(Exception e){
    jspContext.setAttribute("result","发生异常:"+e);
    }
%>

网页运行结果:

 type Exception report
message Unable to compile class for JSP:
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to compile class for JSP: 
An error occurred at line: 40 in the jsp file: /inputnumber.jsp
result cannot be resolved to a variable
37:                 }
38:                 if(a.length()>0&&b.length()>0){
39:             %><computer:computer numberA="<%=a%>" numberB="<%=b%>" operator="<%=operator%>" />
40:             璁$畻缁撴灉鏄細<%=a%><%=operator%><%=b%>=<%=result%>
41:                 <%}%>
42:         </font>
43:     </body>
  • 写回答

3条回答 默认 最新

  • Neoze 2015-11-19 09:41
    关注

    乱码了,编码不对,你试试把中文去掉,如果正常了就是编码问题,检查下你对容器编码设置

    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序