jsp継続学習(requestオブジェクト)

3730 ワード

Action処理ページの名前、method提出方法
request.getParameterはtextタイプのコミット内容を取得し、textタイプのnameに続く
request.getParameterValuesはcheckboxタイプの選択したvalueを得ることができ、checkboxタイプのnameに続く
こちらはIndexページ
<%@ page language="java" import="java.util.*"  contentType="text/html;charset=UTF-8" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>My JSP 'index.jsp' starting page</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
  </head>
  
  <body>
     <h1>   request  </h1><br>
     <%--action        ,method     --%>
     <form name="reForm" action="request.jsp" method="post">
     <table>
     <tr>
     <td>   :</td>
     <td><input type="text" name="username"></td>
     </tr>
     <tr>
     <td>  :</td>
     <td><input type="checkbox" name="favourite" value="read">  
     <input type="checkbox" name="favourite" value="music">  
     <input type="checkbox" name="favourite" value="movie">  
     <input type="checkbox" name="favourite" value="internet">  
     </td>
     </tr>
     <tr>
     <td colspan="2">
     <input type="submit" value="  ">
     </td>
     </table>
     </form>
  </body>
</html>
request.jspです
<%@ page language="java" import="java.util.*" contentType="text/html;charset=utf-8"%>
<%@ page  import="java.text.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>    </title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
  </head>
  
  <body>
  <% request.setCharacterEncoding("utf-8"); //        %>
  
        :<%= request.getParameter("username") %><br>
       :  <% 
     String[] favorites=request.getParameterValues("favourite");
     for (int i=0;i<favorites.length;i++)
     {
     out.println(favorites[i]+"  ");
     }
     %>
  </body>
</html>