将整型值转为字符串

StringUtil6.java

public class StringUtil6 {
    private int intValue=0;
    private String strValue1;
    private String strValue2;
    private String strValue3;
    public StringUtil6(){}
    public int getIntValue() {
        return intValue;
    }
    public void setIntValue(int intValue) {
        this.intValue = intValue;
    }
    public String getStrValue1() {
        return String.valueOf(intValue);
    }
    public void setStrValue1(String strValue1) {
        this.strValue1 = strValue1;
    }
    public String getStrValue2() {
        return Integer.toString(intValue);
    }
    public void setStrValue2(String strValue2) {
        this.strValue2 = strValue2;
    }
    public String getStrValue3() {
        return Integer.valueOf(intValue).toString();
    }
    public void setStrValue3(String strValue3) {
        this.strValue3 = strValue3;
    }
    
}

index.jsp

<body>
    <%
        int userAge=35;
    %>
    <jsp:useBean id="strBean" class="com.count.StringUtil6"></jsp:useBean>
    <jsp:setProperty property="intValue" name="strBean" value="<%=userAge %>"/>
    <table>
        <tr bgcolor="skyblue">
            <td align="center">String.valueOf():</td>
        </tr>
        <tr>
            <td align="center">Age:<jsp:getProperty property="strValue1" name="strBean"/>岁</td>
        </tr>
        <tr bgcolor="skyblue">
            <td align="center">Integer.toString():</td>
        </tr>
        <tr>
            <td align="center">Age:<jsp:getProperty property="strValue2" name="strBean"/>岁</td>
        </tr>
        <tr bgcolor="skyblue">
            <td align="center">Integer.valueOf().toString():</td>
        </tr>
        <tr>
            <td align="center">Age:<jsp:getProperty property="strValue3" name="strBean"/>岁</td>
        </tr>
    </table>
</body>
7.PNG
8.PNG
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • /Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home...
    光剑书架上的书阅读 3,967评论 2 8
  • JSP总结(经典) day1 JSP 定义: 1)Java Server Page, Java EE 组件,本...
    java日记阅读 3,529评论 0 13
  • 1.学习内容 JSP技术入门和常用指令 JSP的内置对象&标签介绍 EL表达式&EL的内置对象 2.JSP技术入门...
    WendyVIV阅读 2,180评论 1 18
  • 市场上,香椿52元一斤时,那菠菜才5角一斤。 富人举着一把香椿对那个举着一捆菠菜的穷人说:“5毛钱一斤的菠菜,能吃...
    刘万军L阅读 180评论 1 1
  • 主人养了三只小龟,随着时间的推移,小龟们越来越大,它们的龟缸越发拥挤,可粗心的主人并没发现这点。 小龟们决定凭借自...
    余独不觉乐妈阅读 366评论 2 7