【greeting.jsp】
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%!
private static final String DEFAULT_USER = "宾客";
%>
<%
String user = request.getParameter("user");
if(user == null){
user = DEFAULT_USER;
}
%>
<html>
<head>
<title>Title</title>
</head>
<body>
你好,<%= user%>!<br/><br />
<form action="greeting.jsp" method="post">
Enter your name:<br/>
<input type="text" name="user" /><br />
<input type="submit" value="Submit"/>
</form>
</body>
</html>
【多值jsp】
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
String[] fruits = request.getParameterValues("fruits");
%>
<html>
<head>
<title>Title</title>
</head>
<body>
<h2>欢迎随意挑选</h2>
<%
if (fruits==null){
%>欢迎下次光临<%
}else{
for(String fruit:fruits){
out.println(fruit);
}
}%>
</body>
</html>