How to create a simple java web application using servlet? I will show you in STEP BY STEP. Please keep it as your note forever!
Step 1: Create a new Dynamic Web Project
Step 2: Create classes as objects that is managed.
Step 3: Create database
Step 4: Connect your project to database
Step 5: Start Server.
Server is Tomcat, Starfish, etc.
Step 6: Create a JSP file called index.jsp under WEB-INF folder.
This file is known as the HOME page of the site.
Step 7: Run this index.jsp file as an example for the first time to simplify. By the way:
Right click on index.jsp file and choose Run on Server. After that, Java IDE will automatically start the server and run the program.
If success, you will see the new tab which show the website contains something like Hello World page. If not, check your server and program again.
Step 8: Create new Servlet file call HelloServlet as an example which is under a package with the name as your wish that under "Java Resouces/src" folder.
Step 9: Add new content on the file called web.xml under WEB-INF folder.
As an example:
<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>tvvkiet.ctu.tvk4men.servlet.HelloServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/chao-the-gioi</url-pattern>
</servlet-mapping>
Description:
"HelloServlet" is the name of the servlet file
"tvvkiet.ctu.tvk4men.servlet" is the name of the package which contains "HelloServlet" file
"/chao-the-gioi" is the new addition URL of this file when it was run on server.
Another part is must be as it is before.
Step 10: Develop the real application here.
KEEP UPDATING...!
Thanks a lot!
Kiet Tram
From Vietnam
Step 1: Create a new Dynamic Web Project
Step 2: Create classes as objects that is managed.
Step 3: Create database
Step 4: Connect your project to database
Step 5: Start Server.
Server is Tomcat, Starfish, etc.
Step 6: Create a JSP file called index.jsp under WEB-INF folder.
Index file is the first file was load when the website is running |
Step 7: Run this index.jsp file as an example for the first time to simplify. By the way:
Right click on index.jsp file and choose Run on Server. After that, Java IDE will automatically start the server and run the program.
If success, you will see the new tab which show the website contains something like Hello World page. If not, check your server and program again.
Step 8: Create new Servlet file call HelloServlet as an example which is under a package with the name as your wish that under "Java Resouces/src" folder.
Step 9: Add new content on the file called web.xml under WEB-INF folder.
As an example:
<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>tvvkiet.ctu.tvk4men.servlet.HelloServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/chao-the-gioi</url-pattern>
</servlet-mapping>
Description:
"HelloServlet" is the name of the servlet file
"tvvkiet.ctu.tvk4men.servlet" is the name of the package which contains "HelloServlet" file
"/chao-the-gioi" is the new addition URL of this file when it was run on server.
Another part is must be as it is before.
Step 10: Develop the real application here.
KEEP UPDATING...!
Thanks a lot!
Kiet Tram
From Vietnam
Comments
Post a Comment