隨筆 - 20  文章 - 57  trackbacks - 0
          <2010年12月>
          2829301234
          567891011
          12131415161718
          19202122232425
          2627282930311
          2345678

          常用鏈接

          留言簿(2)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          51CTO

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          通過以下Servlet程序和web.xml來說明web.xml的配置以及過程


          創(chuàng)建一個Login的HTML文件



          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
          <html>
            <head>
              <title>login.html</title>
             
              <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
              <meta http-equiv="description" content="this is my page">
              <meta http-equiv="content-type" content="text/html; charset=UTF-8">
           
           </head>
            <body>
              <form action="test1" method="post">
                <table border="0" width="379" height="79">
                  <tr>
                    <td>帳號:</td>
                    <td><input type="text" name="username"></td>
                  </tr>
                  <tr>
                    <td>密碼:</td>
                    <td><input type="password" name="password"></td>
                  </tr>
                  <tr>
                    <td colspan="5" align="center"><input type="submit" value="登錄"></td>
                  </tr>
                </table>
              </form>
            </body>
          </html>



          以上HTML標簽中要說明的是:
          <form>標簽中的 action="test_Web_xml" 和 method="post" 分別定義了Html將登陸的信息發(fā)送給了誰,以及發(fā)送信息的方法!


          創(chuàng)建一個Servlet程序

          public class LoginServlet extends HttpServlet{
             
              public void doPost(HttpServletRequest request, HttpServletResponse response)
                  throws ServletException, IOException {
                  String username = null;
                  username = request.getParameter("username");
                  String password = null;
                  password = request.getParameter("password");
                 
                  if(username.equals("username")&&password.equals("password")){
                      request.getRequestDispatcher("成功登陸!!!").forward(request,response);
                  }else{
                      request.getRequestDispatcher("登陸失?。。。?).forward(request,response);   
                  }
              }
          }



          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">
            
             
              <servlet>
                <servlet-name>
                Login
                </servlet-name>
               
                <servlet-class>
                  com.rise.LoginServlet
                  </servlet-class>
               </servlet>
           
           
               <servlet-mapping>
                <servlet-name>
                 Login
                </servlet-name>
                <url-pattern>
                /test1

                </url-pattern>

               </servlet-mapping>
             
             
             
            <welcome-file-list>
              <welcome-file>index.jsp</welcome-file>
            </welcome-file-list>
          </web-app>



          我理解web.xml的作用就是將頁面和后臺程序正確連接?。?!



          通過一張圖片說明我理解的web.xml的作用






          以上的內(nèi)容是我自己對web.xml的理解,我覺得很簡單,但真正寫程序的時候部署程序是非常復雜的!

          posted on 2010-12-11 20:43 tovep 閱讀(6317) 評論(2)  編輯  收藏

          FeedBack:
          # re: Servlet中web.xml配置 2010-12-12 19:27 愛品者
          樓主說了一部分,還有更重要的就是非授權(quán)跳轉(zhuǎn),光靠servlet是不夠的,必須有filter配合  回復  更多評論
            
          # re: Servlet中web.xml配置 2011-11-09 16:45 質(zhì)量
          講的很好  回復  更多評論
            

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導航:
          博客園   IT新聞   Chat2DB   C++博客   博問  
           
          主頁 主站蜘蛛池模板: 晋宁县| 县级市| 涞源县| SHOW| 大宁县| 汾阳市| 汨罗市| 乌兰察布市| 莱西市| 柯坪县| 信丰县| 古浪县| 珲春市| 淄博市| 安徽省| 咸丰县| 衡阳市| 施秉县| 龙陵县| 巴楚县| 湟源县| 宣威市| 靖西县| 仪征市| 土默特左旗| 乌兰察布市| 扎兰屯市| 共和县| 尉氏县| 元氏县| 吉首市| 乌审旗| 甘谷县| 太仓市| 宁乡县| 阿图什市| 清徐县| 五莲县| 涟源市| 城固县| 得荣县|