StringUtil.java
public class StringUtil {
private String str;
public void setStr(String str){
this.str= str;
}
public String getStr(){
return replace(str);
}
private String replace(String str) {
String newString="";
String newString2="";
newString=str.replace("", " ");
newString2=newString.replaceAll("\r\n", "<br>");
return newString2;
}
}
index.jsp
<body>
<form action="replace.jsp" method="post">
<table>
<tr><td align="center">请输入信息</td>
</tr>
<tr>
<td><textarea rows="5" cols="30" name="info"></textarea></td>
</tr>
<tr>
<td align="center"><input type="submit" value="提交"/></td>
</tr>
</table>
</form>
</body>
replace.jsp
<body>
<%
String info=request.getParameter("info");
%>
<jsp:useBean id="strBean" class="com.count.StringUtil"></jsp:useBean>
<jsp:setProperty property="str" name="strBean" value="<%=info %>"/>
<table width="240">
<tr>
<td align="center">查看信息结果</td></tr>
<tr>
<td height="100" valign="top">
<jsp:getProperty property="str" name="strBean"/></td></tr>
</table>
</body>
24.PNG
25.PNG
网友评论