zoukankan      html  css  js  c++  java
  • 关于JSP与Int不得不说的故事

    今天遇到一个问题,我在一个一个jsp中有一个input type="radio",该radio的值放到了session.getAttribute("sex")中,这时候要展示页面的时候需要判断从sql获取的值到底是哪个radio,  so,我写了一下判断

    <% if((int)session.getAttribute("sex")==0){%>
    <input type="radio" name="ia.sex" value="0" checked="checked"/>男
    <input type="radio" name="ia.sex" value="1" />女
    <% }else if((int)session.getAttribute("sex")==1){%>
    <input type="radio" name="ia.sex" value="0" />男
    <input type="radio" name="ia.sex" value="1" checked="checked"/>女
    <% }%>

    但是这时候一发布发现一个问题!

    报错:

     Unable to compile class for JSP:                 

    An error occurred at line: 68 in the jsp file: /success/logdata.jsp

    Cannot cast from Object to int

    什么意思呢?

    无法编译Jsp:
    行有一个错误:68在JSP文件:/成功/ logdata.jsp
    不能投到int的对象

    然后我就将int换为Integer,如下

    <% if((Integer)session.getAttribute("sex")==0){%>
    <input type="radio" name="ia.sex" value="0" checked="checked"/>男
    <input type="radio" name="ia.sex" value="1" />女
    <% }else if((Integer)session.getAttribute("sex")==1){%>
    <input type="radio" name="ia.sex" value="0" />男
    <input type="radio" name="ia.sex" value="1" checked="checked"/>女
    <% }%>

    运行!OK,所以

    JSP这个大坑货居然不认识Int!!!

  • 相关阅读:
    day27_递归
    Linux常用命令
    Linux中的标准输入输出文件
    秋招日记《三》——字节三面挂
    《秋招日记》阿里一面
    秋招日记<->PDD一面挂
    十大排序
    第 254 场周赛 数组元素的最小非零乘积
    找不到boost/bind.hpp
    如何在Google浏览器中批量下载网页上的图片
  • 原文地址:https://www.cnblogs.com/zzxxll/p/5485291.html
Copyright © 2011-2022 走看看