<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # 創建JavaWeb目錄:hello ```[video] src: 'http://www.baishenghua.cn/video/JavaWeb1_3.mp4' autoplay: true ``` #### **一、創建hello項目** >1. 在webapps目錄下創建一個hello目錄,hello目錄就是項目目錄了; >2. 在hello目錄下創建WEB-INF >3. 在WEB-INF下創建web.xml >4. 在WEB-INF下創建classes目錄 >5. 在WEB-INF下創建lib目錄 >6. 在hello目錄下創建index.html   在web.xml文件中添加如下內容: ``` <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> </web-app> ```   在index.html中添加如下內容: ``` <html> <head> <!--如果是html頁面,charset設置為gb2312或者UTF-8,可以防止出現亂碼--> <meta charset="gb2312"/> <title>index.html</title></head> <body> <h1>hello主頁</h1> </body> </html> ``` >[success]啟動tomcat,打開客戶端訪問http://localhost:8080/hello/index.html ***** #### **二、創建學生信息采集系統** ### 修改index.html里面的內容如下: ``` <html> <head> <meta charset="gb2312"/> <title>學生信息采集系統</title> </head> <body> <center> <h1>學生信息采集</h1> <!-- method的值有兩個,一個是get,一個是post--> <form action="" method="get"> 年級:<input type="text" name="grade"/><br> 班級:<input type="text" name="classe"/><br> 專業:<input type="text" name="profe"/><br> 學號:<input type="text" name="studentNO"/><br> 姓名:<input type="text" name="name"/><br> 手機:<input type="text" name="phone"/><br> 密碼:<input type="password" name="pwd"/><br> <input type="submit" /> </center> </form> </body> </html> ``` 當method的值為get時,我們在頁面輸入完數據進行提交如下圖所示: ![](http://h.yiniuedu.com/f91be338d35d5ee3e2d4a7cef2ef5eb5) >[danger]上面的ip地址為局域網地址,大家在自己電腦上可以使用127.0.0.1訪問 注意:看紅色框,會在地址欄顯示你注冊時提交的信息,這種方式相對來說不夠安全 ``` <html> <head> <meta charset="UTF-8"/> <title>學生信息采集系統</title> </head> <body> <center> <h1>學生信息采集</h1> <!-- method的值有兩個,一個是get,一個是post--> <form action="" method="post"> 年級:<input type="text" name="grade"/><br> 班級:<input type="text" name="classe"/><br> 專業:<input type="text" name="profe"/><br> 學號:<input type="text" name="studentNO"/><br> 姓名:<input type="text" name="name"/><br> 手機:<input type="text" name="phone"/><br> 密碼:<input type="password" name="pwd"/><br> <input type="submit" /> </center> </form> </body> </html> ``` 當method的值為post時,我們在頁面輸入完數據進行提交如下圖所示: ![](http://h.yiniuedu.com/5621c27a7d1f221370eed294135a248e) >[danger]上面的ip地址為局域網地址,大家在自己電腦上可以使用127.0.0.1訪問 大家注意看地址欄,不會顯示你注冊時提交的信息,相對安全一點。 #### **三、實現注冊功能(兩個JSP頁面間跳轉)** ***** >把上面的index.html改為index.jsp。 然后 index.jsp里面添加如下內容: ``` <%@page language="java" contentType="text/html;charset=GB2312" pageEncoding="GB2312"%> <html> <head> <!--如果是jsp頁面,charset設置為GB2312,可以防止出現亂碼--> <meta charset="GB2312"> <title>張三豐的博客</title></head> <body> <h1>歡迎來到張三豐的博客</h1> <form action="login.jsp" method="post"> 賬號:<input type="text" id="account" name="account"/><br> 密碼:<input type="password" id="pwd" name="pwd"/><br> <input type="submit" /> </form> <table> <tr><td>序號</td><td>姓名</td></tr> <% for(int i=0;i<10;i++){%> <tr><td><%=i%></td><td>張<%=i%></td></tr> <% } %> </table> </body> </html> ``` 在hello目錄下創建login.jsp,然后在login.jsp里面添加如下內容: ``` <%@page language="java" contentType="text/html;charset=GB2312" pageEncoding="GB2312"%> <html> <head> <meta charset="GB2312"> <title>張三豐的博客</title></head> <body> <h1>歡迎來到張三豐的博客</h1> <% String account = request.getParameter("account"); String pwd = request.getParameter("pwd"); %> 你的賬號為:<%=account%><br> 密碼為:<%=pwd%> </body> </html> ``` 部分同學可能會出現亂碼,大家可以再tomcat的conf目錄下找到server.xml文件,然后再該文件里面增加URIEncoding="GB2312",如下代碼所示: ``` ?<Connector?URIEncoding="GB2312" port="8080"??maxHttpHeaderSize="8192" maxThreads="150" minSpareThreads="25" maxSpareThreads="75" enableLookups="false" redirectPort="8443" acceptCount="100" connectionTimeout="20000" disableUploadTimeout="true" /> ``` >[success]啟動tomcat,打開客戶端訪問http://localhost:8080/hello/index.jsp ***** 關于亂碼問題 終于解決了jsp頁面之間的傳值問題,總結如下: 源代碼,index.jsp往login.jsp傳值: 現象:中文亂碼,比如“??????” 解決方法如下: >[success]推薦方法三和方法四兩個一起用 其它可供參考方法如下: >方法一: 1.?在b.jsp中把pageEncoding="GB2312"改為pageEncoding="ISO8859-1" 雖然這樣b.jsp頁面顯示的內容還是亂碼,但是不是那種“??????”的亂碼,而是一些特殊字符 2.?然后在瀏覽器中查看菜單中修改成GB2312的編碼,這時亂碼就顯示中文了。 3.但是這種方法是不可行的。 >方法二: 1.在b.jsp中把String name=request.getParameter("name");修改為 String name=new String(request.getParameter("name").getBytes("ISO-8859-1"),"GB2312"); 2.? 這時再在頁面上顯示,則就是中文了。 3.?但是我個人不喜歡這種方法,因為編寫起來代碼非常繁瑣 >方法三: 1.?有人說修改get/post的傳值方式,但是這是有前提的,如果只是把get方式修改成post方式,頁面結果還是亂碼! 2.?前提你必須配置了過濾器,若果你只是配置了過濾器,則傳值方式必須是:post方式才不是亂碼,如果是get方式照樣是亂碼! 3.?過濾器的配置,我想大家都能有,我就不說了 >方法四: 1.有人說配置tomcat的配置文件server.xml里這句: ?<Connector?URIEncoding="GB2312" port="8080"?? maxHttpHeaderSize="8192" ?????????????? maxThreads="150" minSpareThreads="25" maxSpareThreads="75" ?????????????? enableLookups="false" redirectPort="8443" acceptCount="100" ?????????????? connectionTimeout="20000" disableUploadTimeout="true" /> 加上這句:URIEncoding="GB2312" 2.雖然可以但是有前提的,若果你過濾器沒有配置,則只是配置了server.xml文件,這樣只有在表單是get傳值時候才可以!當是post方式時,照樣是亂碼! \*這時我們就可以看出在tomcat5中的post與get傳值方式是不一樣的\* \*有人要問有沒有一種方法讓傳值使用get方式或post方式都好用呢,下面就是我推薦的方法五\* >方法五: 1.其實很簡單,就是同時實現方法三又實現方法四! 2.就是先配置過濾器,又配置server.xml文件,都設置成GB2312的編碼 3.這樣無論是post還是get方式的表單傳值,中文都不會是亂碼! >[danger]注意:不能在IDEA或者Eclipse中開啟tomcat的同時,然后再次在bin目錄下雙擊startup.bat打開,這是不被允許的。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看