07-String类型转换为整型(字符串处理)

来源:互联网 发布:幽默高质量的笑话 知乎 编辑:程序博客网 时间:2024/05/01 23:00

StringUtil.java

package com.lh.bean;public class StringUtil {// 第一种方法转换后的Int值private int intValue1;// 第一种方法转换后的Int值private int intValue2;// 被转换的字符串private String strValue;// 默认构造方法public StringUtil() {}// 使用Integer类的parseInt()方法进行转换public int getIntValue1() {return Integer.parseInt(strValue);}// 使用Integer类的valueOf()方法进行转换public int getIntValue2() {return Integer.valueOf(strValue);}public String getStrValue() {return strValue;}public void setStrValue(String strValue) {this.strValue = strValue;}}


 

index.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><html><head><title>index.jsp</title></head><body><%String strAge = "26";%><!-- 使用userBean动作导入StringUtil类 --><jsp:useBean id="strBean" class="com.lh.bean.StringUtil"></jsp:useBean><!-- 对StringUtil类对象中的strValue属性赋值 --><jsp:setProperty property="strValue" name="strBean"value="<%=strAge %>" /><table><tr bgcolor="skyblue"><td align="center">使用Integer.parseInt()方法转换字符串:</td></tr><tr><td align="center"><!-- 获得StringUtil类对象中的IntValue1属性值 --> 年龄1:<jsp:getPropertyproperty="intValue1" name="strBean" />岁</td></tr><tr bgcolor="skyblue"><td align="center">使用Integer.valueOf()方法转换字符串:</td></tr><tr><td align="center"><!-- 获得StringUtil类对象中的IntValue2属性值 --> 年龄2:<jsp:getPropertyproperty="intValue2" name="strBean" />岁</td></tr></table></body></html>


原创粉丝点击