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

淺談Netbeans中Tomcat服務(wù)器配置

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

Netbeans Tomcat服務(wù)器實例配置

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

2。發(fā)布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:

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

docBase的典型結(jié)構(gòu)是:

*.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. 弄清了結(jié)構(gòu),然后自己動手寫一個簡單
新建一個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下就訪問到了
發(fā)現(xiàn)有時候要編譯兩次才能顯示正確的結(jié)果
連接一個圖片時, 文件名竟然是大小寫敏感的
 netbeans的web sample下有tomcat servlet的例子, 是學(xué)習(xí)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開發(fā)PHP應(yīng)用程序
  3. NetBeans 6.0預(yù)覽版發(fā)布 Sun再引驚呼
  4. 使用Netbeans操作MySQL數(shù)據(jù)庫
  5. 八大技術(shù)牛人點評NetBeans 6.5
責(zé)任編輯:張燕妮 來源: csdn
相關(guān)推薦

2009-06-11 09:04:00

2019-01-09 13:07:26

Tomcat服務(wù)器優(yōu)化

2009-06-11 10:03:57

NetBeans代碼

2010-09-29 16:12:09

cisco交換機DHC

2010-08-25 14:40:49

DHCP服務(wù)器故障

2009-06-15 13:46:00

netbeans配置hibernate

2009-07-17 12:44:01

NetBeans開發(fā)S

2011-07-04 17:48:16

IBM服務(wù)器

2011-09-29 13:52:57

服務(wù)器HPC浪潮TS850

2010-01-06 09:19:45

2009-07-09 10:25:05

Servlet的Web

2019-04-23 10:48:55

HTTPTomcat服務(wù)器

2011-06-24 17:23:18

主服務(wù)器從服務(wù)器同步

2020-02-12 13:58:24

服務(wù)器高級優(yōu)化

2013-07-23 09:51:32

Tomcat性能優(yōu)化服務(wù)器性能優(yōu)化

2013-08-12 10:14:42

服務(wù)器虛擬化虛擬化

2010-09-27 11:16:27

DHCP服務(wù)器動態(tài)分配

2011-07-27 15:11:02

2010-08-26 13:04:06

DHCP服務(wù)器

2009-04-03 15:14:42

微軟優(yōu)化SQL Server
點贊
收藏

51CTO技術(shù)棧公眾號

主站蜘蛛池模板: 国产欧美精品一区二区色综合朱莉 | 91在线看| 91精品中文字幕一区二区三区 | 成人免费在线视频 | 国产成人精品在线播放 | 夜夜草 | 国产精品免费一区二区三区四区 | 国产91在线 | 亚洲 | 成人在线视频免费观看 | 欧美成人一区二区 | 四虎影视免费观看 | 国产乱码精品一区二区三区五月婷 | 少妇一区二区三区 | 国产综合视频 | 中国三级黄色录像 | 亚洲成av片人久久久 | 久久久久久黄 | 日韩精品一区二区三区在线观看 | 国产一区二区在线免费播放 | 亚洲精品乱码久久久久久9色 | 国产成人精品久久二区二区91 | 97国产在线视频 | 97国产一区二区精品久久呦 | 亚洲 自拍 另类 欧美 丝袜 | 中文字幕一区二区三区四区五区 | 毛片免费看 | 自拍偷拍中文字幕 | 国产精品一区二区三级 | av中文字幕在线播放 | 日韩av一区二区在线观看 | 欧美日韩一区二区在线观看 | 成人黄色av网站 | 天天干天天草 | 亚洲一区二区在线播放 | 亚洲精品久久嫩草网站秘色 | 成人免费在线播放 | 精品乱子伦一区二区三区 | av午夜电影 | 另类专区亚洲 | 成人欧美日韩一区二区三区 | 伊人伊人伊人 |