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 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥30 最小化遗憾贪心算法上界
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。