Saturday, May 24, 2014

Java EE 105 Create Dynamic Web Project

---
Java EE 105 Create Dynamic Web Project
This tutorial is based on http://www.youtube.com/watch?v=MSS0Tndfh6I
STEPS
1) Run Eclipse.
2) Create New Dynamic Web Project.
3) Fill in project configuration details.
4) Project folders.
5) Web module settings.
6) Project Creation done.
7) Inspect project folder items.
8) Add Servlet file.
9) Run.

STEPS

1) Run Eclipse.

2) Create New Dynamic Web Project.

Go to menu File/New/Dynamic Web Project.

3) Fill in project configuration details.

4) Project folders.

Accept default.

5) Web module settings.

Accept default.

6) Project Creation done.

7) Inspect project folder items.

7.1) JAX-WS Web Services

7.2) Deployment Descriptor: ServletsJSPExample

7.3) Servlet Mappings

7.4) Java Resources

7.5) JavaScript Resources

7.6) WebContent

8) Add Servlet file.

8.1) Right-Click ServletJSPExample project name, select New/Servlet
8.2) Specify class file destination.
8.3) Servlet deployment descriptor information.
8.4) Specify modifiers, interfaces to implement, and method stubs to generate.
8.5) ServletExample.java is created.
8.6) Following the step 8.5, web.xml has been updated with <servlet> and <servlet-mapping> tag.
8.7) Edit ServletExample.java.
Edit public class ServletExample extends HttpServlet {…} as follows:

public class ServletExample extends HttpServlet {
        private static final long serialVersionUID = 1L;
       
        /**
         * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response)
         */
        protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
                // TODO Auto-generated method stub
                PrintWriter out=response.getWriter();
                out.println("Hello Java!");
        }

9) Run.

9.1) Click Run/Run As/Run on Server.
9.2) Set which server to use.
9.3) Click Finish.
9.4) You may need to restart your server if necessary.
9.5) Outcome:

10) ADDITIONAL INFORMATION: Deployment Path.

10.1) Browse the physical storage on server, eg {TOMCAT_HOME}\wtpwebapps
10.2) Why was the project deployed to wtpwebapps folder?
Because, that is the folder specified under the Server Settings in Eclipse.
wtpwebapps directory is an eclipse-specific folder created when you run a dynamic web project on Tomcat within eclipse.
webapps directory is within the Tomcat home and it's where you copy over your WAR files manually.
ADDITIONAL REFERENCES:
---

No comments:

Post a Comment