閱讀888 返回首頁    go 阿裏雲 go 技術社區[雲棲]


JSP基礎5

a.jsp----
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.util.*" errorPage="" %>
<html>
<head>
  <title>JSP練習</title>
</head>

<body>
   <form action="b.jsp" method="post" name="frmName">
   <table width="400" border="1" align="center" cellspacing="0">
    <tr>
        <td width="80" height="25" scope="col" align="left">姓名</td>
        <td height="25" scope="col" align="left"><input type="text"  name="name" ></td>
    </tr>
    <tr>
        <td width="80" height="25">性別</td>
        <td height="25"><input type="radio" name="sex"  value="男">男
		                <input type="radio" name="sex"  value="女">女		</td>
    </tr>
    <tr>
        <td width="80" height="25">喜歡的歌手</td>
        <td height="25">
		    <input type="checkbox" name="singer"  value="張歌手">張歌手
			<input type="checkbox" name="singer"  value="李歌手">李歌手
			<input type="checkbox" name="singer"  value="黃歌手">黃歌手
			<input type="checkbox" name="singer"  value="王歌手">王歌手		</td>
    </tr>
    <tr>
        <td height="25" colspan="2" align="center">
		    <input type="submit" name="submit"  value="提交">
			<input type="reset" name="reset"  value="重置">
		</td>
       </tr>
</table>
</form> 


</body>
</html>

b.jsp

<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="https://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Jsp練習</title>
</head>
<%! 
    public String getGBString(String src){
        try{
           if (src == null) return null;
           else{
               src = new String(src.getBytes("ISO-8859-1"), "GBK");
               return src;
           }
        }
        catch (Exception e){
            return null;
        } 
    }      
%>
<body>
<%
    String name = getGBString(request.getParameter("name"));
    String sex = getGBString(request.getParameter("sex"));
    String singers[] = request.getParameterValues("singer"); 
    out.println("姓名:" + name);
    out.println("性別: " + sex);
    int length = java.lang.reflect.Array.getLength(singers);
    for (int i = 0; i < length; i++){
        out.println(getGBString(singers[i]));
    }
%>
</body>
</html>



最後更新:2017-04-02 00:06:49

  上一篇:go spfa優化 SLF LLL
  下一篇:go C#漢字反序輸出