javascript
关于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"/>女
<% }%>
?
但是這時候一發(fā)布發(fā)現(xiàn)一個問題!
報錯:
?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!!!
轉(zhuǎn)載于:https://www.cnblogs.com/zzxxll/p/5485291.html
總結(jié)
以上是生活随笔為你收集整理的关于JSP与Int不得不说的故事的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【repost】Javascript操作
- 下一篇: 一起来啃书——PHP看书