JavaBean专题

将字符串转为整型值

2018-08-18  本文已影响0人  神坛下的我

StringUtil6.java

public class StringUtil6 {
    private int intValue1;
    private int intValue2;
    private String strValue;
    public StringUtil6(){}
    public int getIntValue1() {
        return Integer.parseInt(strValue);
    }
    public void setIntValue1(int intValue1) {
        this.intValue1 = intValue1;
    }
    public int getIntValue2() {
        return Integer.valueOf(strValue);
    }
    public void setIntValue2(int intValue2) {
        this.intValue2 = intValue2;
    }
    public String getStrValue() {
        return strValue;
    }
    public void setStrValue(String strValue) {
        this.strValue = strValue;
    }
    
    
}

index.jsp

<body>
    <%
        String strAge="26";
    %>
    <jsp:useBean id="strBean" class="com.count.StringUtil6"></jsp:useBean>
    <jsp:setProperty property="strValue" name="strBean" value="<%=strAge %>"/>
    <table>
        <tr bgcolor="skyblue">
            <td align="center">Integer.parseInt():</td>
        </tr>
        <tr>
            <td align="center">Age:<jsp:getProperty property="intValue1" name="strBean"/>岁</td>
        </tr>
        <tr bgcolor="skyblue">
            <td align="center">Integer.valueOf():</td>
        </tr>
        <tr>
            <td align="center">Age:<jsp:getProperty property="intValue2" name="strBean"/>岁</td>
        </tr>
    </table>
</body>
9.PNG
上一篇下一篇

猜你喜欢

热点阅读