JSP 字符串连接实例的实现
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<style type="html/css">
<!--
.STYLE1{
font-size:large;
}
-->
</style>
</head>
<body>
<%
request.setCharacterEncoding("UTF-8");
String str1=request.getParameter("str1");
if(str1==null)
str1="";
String str2=request.getParameter("str2");
if(str2==null)
str2="";
%>
<form name="form1" action="concatenate.jsp" method="post">
<div class="STYLE1">字符串连接</div>
字符串1<input type="text" name="str1" value="<%=str1 %>"/>
<br />
字符串2<input type="text" name="str2" value="<%=str2 %>"/>
<hr />
<input name="ok" type="submit" value="连接">
</form>
<p>
<%
//concat是String类的字符串链接函数
String result=str1.concat(str2);
if(result!=null && !result.equals(""))
out.println("结果:"+result);
%>
</p>
</body>
</html>