jsp隐含对象:
xczxcxzcxz
<%
response.sendRedirect("http://www.baidu.com");//重定项:跳转语句。
%>
各个控件的使用举例:
<%@ page contentType="text/html;charset=GBK"%><!--确定编码方式,保证中文显示 -->
<html><!--中文参数的传递-->
<head>
<title>Table Ex</title>
</head>
<body>
<form action="ta.jsp" method="post"><!--post表示表单能够提交中文-->
<textarea cols="30" rows="20" name="nr"></textarea><br/><!--文本框-->
<input type="submit" value="确定">
</form>
<%
request.setCharacterEncoding("GBK");//确定中文参数与之前一致的编码方式
String nr=request.getParameter("nr");//接收参数
if(nr!=null&&nr.length()!=0)//接收后进行双空检查
{
%>
<%= nr.replaceAll("\\n","<br/>") %><!--替换换行符 -->
<%
}
%>
</body>
</html>
-----------------------------------------------------
<%@ page contentType="text/html;charset=GBK"%>
<html><!--下拉列表的使用 -->
<head>
<title>Table Ex</title>
</head>
<body>
<form action="xl.jsp" method="post">
爱好<select name="hobby">
<option value="游泳">游泳</option>
<option value="打篮球">打篮球</option>
<option value="侃大山">侃大山</option>
</select>
<input type="submit" value="提交">
</form>
<%
request.setCharacterEncoding("GBK");
String nr=request.getParameter("hobby");
if(nr!=null&&nr.length()!=0)
{
%>
<%=nr%><!--打印-->
<%
}
%>
</body>
</html>
-----------------------------------------------------
<%@ page contentType="text/html;charset=GBK"%>
<html><!--可多选的下拉列表-->
<head>
<title>Table Ex</title>
</head>
<body>
<form action="xlm.jsp" method="post">
爱好<select name="hobby" multiple>
<option value="游泳">游泳</option>
<option value="打篮球">打篮球</option>
<option value="侃大山">侃大山</option>
</select>
<input type="submit" value="提交">
</form>
<%
request.setCharacterEncoding("GBK");
String[] nr=request.getParameterValues("hobby");//通过requst接收字符串数组
if(nr!=null&&nr.length!=0)
{
for(String s:nr)
{
out.println(s+",");
}
}
%>
</body>
</html>
------------------------------------------------
<%@ page contentType="text/html;charset=GBK"%>
<html><!---复选框的使用-->
<head>
<title>Table Ex</title>
</head>
<body>
<form action="fxk.jsp" method="post">
爱好<br/>
<input type="CheckBox" name="hobby" value="游泳">游泳<br/><!--name相同的复选框为一组-->
<input type="CheckBox" name="hobby" value="旅游">旅游<br/>
<input type="CheckBox" name="hobby" value="打篮球">打篮球<br/>
<input type="submit" value="提交">
</form>
<%
request.setCharacterEncoding("GBK");
String[] nr=request.getParameterValues("hobby");
if(nr!=null&&nr.length!=0)
{
for(String s:nr)
{
out.println(s+",");
}
}
%>
</body>
</html>
-----------------------------------------------------------
<%@ page contentType="text/html;charset=GBK"%><!--确认编码方式,以正确显示中文-->
<html><!--单选按钮组 -->
<head>
<title>Table Ex</title>
</head>
<body>
<form action="dx.jsp" method="post">
爱好<br/>
<input type="radio" name="hobby" value="游泳">游泳<br/>
<input type="radio" name="hobby" value="旅游">旅游<br/>
<input type="radio" name="hobby" value="打篮球">打篮球<br/>
<input type="submit" value="提交">
</form>
<%
request.setCharacterEncoding("GBK");//接收参数之前,确定与之前相同的编码方式
String nr=request.getParameter("hobby");
if(nr!=null&&nr.length()!=0)
{
out.println(nr);
}
%>
</body>
</html>