html学习笔记四

来源:互联网 发布:财务金融知乎 编辑:程序博客网 时间:2024/04/30 18:46

表单标签<form> :必须记住

表单在html中很常用,因为它可以和计算机交互

input部分

 <font-color = "red" font-size = 10>注册表单</font><hr/>        <!--表单中的内容要想提交到服务端,因为服务端无法解析,so就必须加标识 name value-->       <form>   <!--用type来定义输入的属性-->           输入帐号:<input type="text" name = "user" value=""/> <br/>           输入密码:<input type="password" name="psw" /> <br/><!--passward是非明文信息-->           选择性别:<input type="radio" name="sex" value="nan"/>男           <input type="radio" name="sex" value="nv"/>女<br/>           <!--radio是单选框,若name的值不同,是两组,相同是一组,只能选一个-->           选择性别:<input type="radio" name="sex"/>男           <input type="radio" name="sex" checked="chexked"/>女<br/><!--checked默认被选中-->            复选框:<input type="checkbox" name="tech" value="Java" checked="checked" />Java                  <input type="checkbox" value="C++"/>C++                  <input type="checkbox" value="C"/>C                  <input type="checkbox" value="Python"/>Python                  <input type="checkbox" value="Ruby"/>Ruby<br/>           选择文件:<input type="file" name="file" value=""><br/>           图片提交:<input type="image" src="2.jpg"> <br/><!--用图片图标来提交数据-->           <!--隐藏组件开发常用,数据不需要客户端知道。但是服务器需要记录-->           隐藏组件:<input type="hidden" name="Myname" value="Myvalue" /><br/>           我的按钮:<input type="button" value="按钮" onclick="alert('你好,世界')"/> <br/>           提交结果:<!--<input type="reset"/><input type="submit"/><br/>-->                  <input type="reset" value=" 重新填写 " /><!--其实就是表单数据的状态还原-->                  <input type="submit" value="提交结果" />       </form>

<!--向服务端提交数据,表单中的内容必须有name和value属性

用于给服务端获取数据-->

input  上述方法,都必须记住

select和textarea部分

<!--选择部分-->           <select name="country"><!---->               <option>--选中城市--</option>               <option value="TieLing">铁岭</option>               <option value="WeiHai"> 威海</option>               <option value="ZiBo" selected="selected">淄博</option>               <!--selected 默认淄博-->           </select><br/><br/><br/>            <!--个人简介-->           <textarea name="text">           </textarea><br/>



表单格式化

<form>           <table border="2" bordercolor="#00fff" cellpadding="10" cellspacing="0" width="600tx">               <tr>                   <th colspan="2">注册表单:</th>               </tr>               <tr>                   <td>用户名称:</td>                   <td><input type="text" name="user" /></td>               </tr>               <tr>                   <td>输入密码:</td>                   <td><input type="password" name="pwd" /></td>               </tr>               <tr>                   <td>选择性别:</td>                   <td>                       <input type="radio" name="sex" value="nan">男                       <input type="radio" name="sex" value="nv">女                   </td>               </tr>               <tr>                   <td>选择技术</td>                   <td>                       <input type="checkbox" name="tech" value="Java">Java                       <input type="checkbox" name="tech" value="C++">JC++                       <input type="checkbox" name="tech" value="C">C                       <input type="checkbox" name="tech" value="Python">Python                       <input type="checkbox" name="tech" value="Ruby">Ruby                   </td>               </tr>               <tr>                   <td>选择籍贯</td>                   <td>                       <select name="country" >                           <option value="none">--选择城市--</option>                           <option value="TieLing">铁岭</option>                           <option value="WeiHai">威海</option>                           <option value="ZiBo" selected="selected" >淄博</option>                       </select>                   </td>               </tr>               <tr>                   <th colspan="2">                       <input type="reset" value="清楚数据">                       <input type="submit" value="数据提交">                   </th>               </tr>           </table>       </form>

get和post的区别

将填写好的数据发送到服务端

 <form action="http://www.sina.com" method="get">    //action:服务端链接,method默认是get           <table border="2" bordercolor="#00fff" cellpadding="10" cellspacing="0" width="600tx">               <tr>..
自定义服务端

public static void main(String[] args) throws Exception{        ServerSocket ss = new ServerSocket(9090);        Socket s = ss.accept();        String ip = s.getInetAddress().getHostAddress();        InputStream in = s.getInputStream();        byte[] buf = new byte[1024];        int len = in.read(buf);        String data = new String(buf,0,len);        System.out.println("ps:"+data);        PrintWriter pw = new PrintWriter(s.getOutputStream(),true);        pw.println("<font-color = 'red' font-size='7'>Reg-Suceessful</font>");        ss.close();        s.close();    }

但是对于get和post提交有严重的区别:

1.

get提交:提交的信息都显示在地址栏里

post提交,不显示地址栏

2.

get提交:对于敏感数据信息不安全

post提交:安全

3.

get:因为地址栏空间有限,所以get提交大数据不行

post:可以

4.

get:将数据信息封装到了请求消息的请求行中

post:将数据信息封装到了请求体中

在服务端get和post的区别:

如果出现将中文提交到Tomcat服务器出现乱码的情况(服务器会通过ISO8859-1进行解码,出现乱码)

通过ISO8859-1编码,再用指定的中文码表解码,即可

此方式对get和post提交都有效

PS:对于post提交方式提交的中文,还有另一种方法,就是直接利用服务端的一个对象request对象的setCharacterEncoding方法直接设置指定的中文码表就可以将中文数据解析出来,get不行,此方法只对请求体中的数据进行解码


所以:表单提交,建议用post


和服务端交互的三种方式(重要)

1.地址栏输入url地址,get

2.超链接,get

3.表单:get和post






0 0