日期:2014-05-17 浏览次数:20765 次
<form action="action.jsp" method="post">
<textarea rows="5" cols="30" name="txt"></textarea><br/>
<input type="submit" value="提交"/>
</form>
<body>
<%
request.setCharacterEncoding("GBK");
String sourceStr = request.getParameter("txt").trim();
String lines[] = sourceStr.split(",|,"); //根据中文/英文的逗号分隔字符串为数组
StringBuffer strbuilder = new StringBuffer(); //创建字符串构建器
for(String line:lines){
//把每个数组元素的字符串与回车符相连并添加到字符串构建器中
strbuilder.append(line + "\n");
}
%>
<textarea rows="5" cols="30">
<%=strbuilder.toString() %>
</textarea>
</body>