成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

淺談Netbeans中Tomcat服務器配置

開發 后端
本文詳細介紹了在Netbeans下配置Tomcat。首先需要添加Tomcat服務器,并發布servlet。文章最后還附加了Netbeans Tomcat實例代碼。

Netbeans Tomcat服務器實例配置

1。在netbeans-tools-server manerger下添加tomcat服務器, 默認是已經配置好的。
配置用戶:這個要在base directory 下的tomcat-users.xml文件中設置
用戶角色(role):admin 或者 manager  或者 admin,manager     
Home Directory.服務器所在目錄, 安裝好以后基本不管它的事了
Base Directory: 用戶配置所在目錄, 設置你的服務器和你的servlets                            

2。發布servlet
 
新建一個工程, samples下有tomcat servlet example.命名為TomcatServletExample
在base directory下有apache-tomcat-5.5.17_base\work\Catalina\localhost\servlets-examples\tldCache.ser
在apache-tomcat-5.5.17_base\conf\Catalina\localhost下有depth#examples.xml:

這是以文件夾和文件形式發布的結構。前面提到的servlets-examples.xml文件中的docBase屬性就是我工程文件的目錄, path是制定的訪問路徑, 比如,我這里可以通過http://localhost:8084/servlets-examples/訪問, 客戶端的訪問就是通過這個文件來轉向的

docBase的典型結構是:

*.html, *.jsp, etc :頁面
/WEB-INF/web.xml :he Web Application Deployment Descriptor for your application. This is an XML file describing the servlets and other components that make up your application, along with any initialization parameters and container-managed security constraints that you want the server to enforce for you.

/WEB-INF/classes/ :編譯后的.class文件

/WEB-INF/lib/ :This directory contains JAR files that contain Java class files (and associated resources) required for your application, such as third party class libraries or JDBC drivers.

3. 弄清了結構,然后自己動手寫一個簡單
新建一個web application, 默認有一個index.jsp作為首頁, 首頁可以在web.xml的pages標簽下修改
index.jsp在body標簽下添加: 

Execute

在source packages下添加NewServlet.class, 代碼附在后面
在web.xmlservlet標簽下配置NewServlet, 指定servlet class和url pattern, 我指定的是/NewServlet, 在http://localhost:8084/WebServletTest/NewServlet下就訪問到了
發現有時候要編譯兩次才能顯示正確的結果
連接一個圖片時, 文件名竟然是大小寫敏感的
 netbeans的web sample下有tomcat servlet的例子, 是學習servlet的很好的例子
 
實例代碼:

  1. -------------------------------------  
  2.    
  3. import java.io.*;  
  4. import java.net.*;  
  5. import javax.servlet.*;  
  6. import javax.servlet.http.*;  
  7. public class NewServlet extends HttpServlet {  
  8.     /** Initializes the servlet. Connections to databases belong here !  
  9.      */  
  10.     public void init(ServletConfig config) throws ServletException {  
  11.         super.init(config);  
  12.           
  13.     }  
  14.       
  15.     /** Destroys the servlet. Close connections, files, etc.  
  16.      */  
  17.     public void destroy() {  
  18.           
  19.     }  
  20.      
  21.     // Form values can be passed by 2 methods, GET or POST  
  22.     // the doGet() (resp. doPost())  method is called when the method is   
  23.     // GET (resp POST).  
  24.     // The following trick allows us to process both with one function  
  25.       
  26.     protected void doGet(HttpServletRequest request, HttpServletResponse response)  
  27.     throws ServletException, IOException {  
  28.         processRequest(request, response);  
  29.     }  
  30.       
  31.     protected void doPost(HttpServletRequest request, HttpServletResponse response)  
  32.     throws ServletException, IOException {  
  33.         processRequest(request, response);  
  34.     }  
  35.       
  36.     protected void processRequest(HttpServletRequest request, HttpServletResponse response)  
  37.     throws ServletException, IOException {  
  38.         response.setContentType("text/html");  
  39.         PrintWriter out = response.getWriter();  
  40.           
  41.         out.println("");  
  42.         out.println("");  
  43.         out.println("");  
  44.         out.println("");  
  45.         out.println("");  
  46.  // The real work of the servlet begins here  
  47.    
  48.  // A servlet does nothing else than outputing HTML code  
  49.  // to the webserver. It can output the HTML code corresponding  
  50.  // to a form. The user fills this form and, when the Submit button   
  51.  // is clicked, the values are sent to the appropriate program on the   
  52.  // webserver (in this case, our servlet) which then uses these values  
  53.  // to `calculate' what it should display this time  
  54.    
  55.  // If the servlet is simply   
  56.  // called by visiting an url or clicking a link, all parameters  
  57.  // will have null values. This is what happens when you type  
  58.  // `www.google.com' in your browser. We can detect this and   
  59.  // print out a default `welcome' message (as below).  
  60.  // If the servlet is called by clicking a submit  
  61.  // button, no parameter will have null values (fields not filled  
  62.  // by the user will return empty strings, not null).  
  63.    
  64.         if (request.getParameter("myparam") != null)   
  65.      // the request.getParameter function allows us to obtain the   
  66.      // values entered by the user in the various input fields  
  67.             out.println("Your parameter is "+request.getParameter("myparam")+"  
  68. ");  
  69.         else   
  70.             out.println("Hello, please enter a parameter !  
  71. ");  
  72.  out.println(" Enter your new parameter here:  
  73. ");  
  74.         out.println(  
  75.  // The `action` field of the `form` tag indicates which program   
  76.  // should be called by the webserver when the user clicks `submit'  
  77.  // in this case, we tell it to call the same servlet again  
  78.         " "+  
  79.  // The 'name' of the input field corresponds to the name of the  
  80.  // parameter which will contain the value  
  81.  // entered in this input field (here, it is 'myparam' - see above)  
  82.         "  
  83. "+  
  84.  // The special `submit` input field generates a submit button  
  85.  ""  
  86.  // When the user clicks the submit button, the browser sends a   
  87.  // request to the servlet whose name is contained in the `action`   
  88.  // field of the `` tag, which in this case is the present   
  89.  // servlet. This request includes the values entered by the user   
  90.  // in the different input fields as parameters.  
  91.         +""  
  92.         );  
  93.           
  94.         out.println("");  
  95.         out.println("");  
  96.           
  97.         out.close();  
  98.     }  
  99.      
  100.     public String getServletInfo() {  
  101.         return "Short description";  
  102.     }  
  103.       
  104. }   

【編輯推薦】

  1. 讓Eclipse和NetBeans共享同一個項目
  2. 使用NetBeans和Eclipse開發PHP應用程序
  3. NetBeans 6.0預覽版發布 Sun再引驚呼
  4. 使用Netbeans操作MySQL數據庫
  5. 八大技術牛人點評NetBeans 6.5
責任編輯:張燕妮 來源: csdn
相關推薦

2009-06-11 09:04:00

2019-01-09 13:07:26

Tomcat服務器優化

2009-06-11 10:03:57

NetBeans代碼

2010-08-25 14:40:49

DHCP服務器故障

2009-07-17 12:44:01

NetBeans開發S

2010-09-29 16:12:09

cisco交換機DHC

2009-06-15 13:46:00

netbeans配置hibernate

2011-09-29 13:52:57

服務器HPC浪潮TS850

2011-07-04 17:48:16

IBM服務器

2009-07-09 10:25:05

Servlet的Web

2010-01-06 09:19:45

2020-02-12 13:58:24

服務器高級優化

2013-07-23 09:51:32

Tomcat性能優化服務器性能優化

2011-06-24 17:23:18

主服務器從服務器同步

2019-04-23 10:48:55

HTTPTomcat服務器

2010-08-26 13:04:06

DHCP服務器

2009-04-03 15:14:42

微軟優化SQL Server

2013-08-12 10:14:42

服務器虛擬化虛擬化

2010-09-27 11:16:27

DHCP服務器動態分配

2011-07-27 15:11:02

點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 国产中文字幕在线 | 97久久国产 | 成人教育av | 亚洲综合二区 | 欧美精品一区二区三区四区五区 | 亚洲视频在线观看 | 久久亚洲综合 | 成人激情免费视频 | 91视频进入| 亚洲黄色一级毛片 | 国产日韩久久 | 亚洲精品一区二区在线 | 国产精品成av人在线视午夜片 | 国产精久久久久久久 | 91精品国产综合久久福利软件 | 欧美日韩国产精品一区 | 视频一区在线观看 | 国产在线视频一区二区 | 在线观看视频91 | 中文成人无字幕乱码精品 | 欧美在线视频二区 | 亚洲免费精品 | 国产成人精品综合 | 欧美一区二区大片 | 欧美日韩国产一区二区三区不卡 | 欧美日韩在线一区二区 | 性高湖久久久久久久久 | 日本成人中文字幕 | 欧美精品一区二区三区蜜臀 | 国产偷录叫床高潮录音 | 久久久噜噜噜www成人网 | 亚洲九九精品 | 五月婷婷激情网 | 九热在线| 91精品国产色综合久久 | 成人毛片一区二区三区 | 麻豆国产一区二区三区四区 | 国产日韩欧美中文 | 日本免费一区二区三区 | 成人欧美一区二区三区在线观看 | 天天艹日日干 |