Developing JSP page is easier than Servlet. But Servlet has some benefit over JSP. So if we want to run Servlet by developing our page in JSP then we can do it very easily. Although we know that all JSP page is first converted into Servlet and then run. But it makes JSP slower than Servlet. Since Servlet is written in Java while JSP is written in HTML, so it becomes difficult to design in Servlet. Another headache with Servlet that it requires compilation after every changes in code.
Servlets are best suited for large data processing and manipulation. It can also be best suited where you don't want reveal your file name without using any platform.
So if we want develop our page in JSP because of easiness in design, custom tags for calling Beans and use of JavaScript and run it as Servlet because of speed and processing then we can do it in following way:-
I assume that you have good idea of running Servlet on Apache Tomcat Server.
Create your JSP page/project on any of your favourite IDE with your desired design and save it to your project root directory. Now run this page on your server. If it is OK then do the following-
1. Go to Tomcat home folder ------> Work --------> Catalina ----------> localhost
Here you will see your project folder. Inside this folder you will find org folder.
In org folder, there is another folder apache and then jsp folder. In this jsp folder you will see the all Servlet with the name of your JSP page you have created in your project. These Servlets are created when you run your JSP page on browser (as you know that all JSP are first converted into Servlet before run on browser).
2. Copy this folder (org) to your project/WEB-INF/classes location.
Now in your web.xml, do the Servlet configuration like this.
<servlet>
<servlet-name>sm</servlet-name>
<servlet-class>org.apache.jsp.home1_jsp</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>sm</servlet-name>
<url-pattern>/sm.arv</url-pattern>
</servlet-mapping>
If your server is capable of running Servlet, it will also run.
Like this you can convert your all pages/project in Servlet.
Advantages:-
This kind of work can also hide your business logic of your coding from others when you have to distribute your project or share with others.
Also you can design your page in JSP and run as Servlet and you don't need to compile it everytime (for compilation just run JSP page automatically it will be compiled).
You can also hide your file extension (.htm, .html, .jsp).
Servlets are best suited for large data processing and manipulation. It can also be best suited where you don't want reveal your file name without using any platform.
So if we want develop our page in JSP because of easiness in design, custom tags for calling Beans and use of JavaScript and run it as Servlet because of speed and processing then we can do it in following way:-
I assume that you have good idea of running Servlet on Apache Tomcat Server.
Create your JSP page/project on any of your favourite IDE with your desired design and save it to your project root directory. Now run this page on your server. If it is OK then do the following-
1. Go to Tomcat home folder ------> Work --------> Catalina ----------> localhost
Here you will see your project folder. Inside this folder you will find org folder.
In org folder, there is another folder apache and then jsp folder. In this jsp folder you will see the all Servlet with the name of your JSP page you have created in your project. These Servlets are created when you run your JSP page on browser (as you know that all JSP are first converted into Servlet before run on browser).
2. Copy this folder (org) to your project/WEB-INF/classes location.
Now in your web.xml, do the Servlet configuration like this.
<servlet>
<servlet-name>sm</servlet-name>
<servlet-class>org.apache.jsp.home1_jsp</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>sm</servlet-name>
<url-pattern>/sm.arv</url-pattern>
</servlet-mapping>
If your server is capable of running Servlet, it will also run.
Like this you can convert your all pages/project in Servlet.
Advantages:-
This kind of work can also hide your business logic of your coding from others when you have to distribute your project or share with others.
Also you can design your page in JSP and run as Servlet and you don't need to compile it everytime (for compilation just run JSP page automatically it will be compiled).
You can also hide your file extension (.htm, .html, .jsp).