官术网_书友最值得收藏!

Running JSP in Tomcat

To run the JSP we created in the previous section in the web browser, you will need to deploy the application in a servlet container. We have already seen how to configure Tomcat in Eclipse. Make sure that Tomcat is running by checking its status in the Servers view of Eclipse:

Figure 2.15: Tomcat started in the Servers view

There are two ways to add a project to a configured server so that the application can be run on the server:

  1. Right-click on the server in the Servers view and select the Add and Remove option. Select your project from the list on the left (Available resources) and click Add to move it to the Configured list. Click Finish.

Figure 2.16: Add a project to the server

  1. The other method to add a project to the server is to right-click on the project in Project Explorer and select Properties. This opens the Project Properties dialog box. Click on Server in the list and select the server in which you want to deploy this project. Click OK or Apply.

Figure 2.17: Select server in project properties

In the first method, the project is immediately deployed in the server. In the second method, it will be deployed only when you run the project in the server.

  1. To run the application, right-click on the project in Project Explorer and select Run As | Run on Server. The first time you will be prompted to restart the server. Once the application is deployed, you will see it under the selected server in the Servers view:

Figure 2.18: Project deployed on the server

  1. Enter some text other than admin in the username and password boxes
    and click Submit. You should see the error message and the same form should be displayed again.

Figure 2.19: Project running in the built-in browser in Eclipse

  1. Now enter admin as username and password and then submit the form. You should see the welcome message.

JSPs are compiled dynamically to Java classes, so if you make any changes in the page, in most cases, you do not have to restart the server; just refresh the page, and Tomcat will recompile the page if it has changed and the modified page will be displayed. In cases when you need to restart the server to apply your changes, Eclipse will prompt you if you want to restart the server.

主站蜘蛛池模板: 敦煌市| 宜兴市| 台安县| 图们市| 海南省| 辉南县| 应城市| 鲜城| 双牌县| 喀喇| 靖安县| 信丰县| 太白县| 尉犁县| 金塔县| 平凉市| 张北县| 长白| 吴堡县| 吴忠市| 通渭县| 陆河县| 栖霞市| 枣庄市| 达拉特旗| 通化县| 铜山县| 肥东县| 额济纳旗| 原阳县| 沭阳县| 瓦房店市| 凤山市| 孟津县| 灯塔市| 昭通市| 绩溪县| 十堰市| 弥勒县| 梁山县| 陕西省|