JSP——2

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>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值