Finishing the Project: Java Web Development in Eclipse and Tomcat
Last week, I introduced you to some of the fundamental concepts you need for working with Java web components. For this project we'll be working with JSP and servlets. I walked you through getting the appropriate downloads installed and setting up your work space. We stopped after just creating the web project. In this part, we will add our content, including HTML, JSP, and servlets.
Finishing the Project: Java Web Development in Eclipse and Tomcat - What just happened? (Page 4 of 4 )
You must be wondering what happened. How can Welcome aboard <%=username%> dynamically become Welcome aboard user? How are the user name and password entered in the login.html page being carried over to welcome.jsp? This brings us to another important Java web component called Servlet.
First, the parameters entered in the form fields are carried over from login.html to welcome.jsp by the request object.
You'll find welcome_jsp.java and welcome_jsp.class, which are compiled from Java. Those two files are created and managed by the Eclipse environment.
Let's import welcome_jsp.java into Eclipse IDE to see the details.
First, highlight the Java Resources folder, then from the content menu, select import -> File System.
Then browse into the directory above.
Click Finish, and the Java code shows on the Eclipse content panel. Below is the full text; you can instantly recognize that the red portion is from welcome.jsp
Now you have figured out the relationship between JSP and Servlet! Let's go a step further to prove that JSP actually is the text form of the Servlet class.
The web.xml defines the Servlet we just imported from and the servlet-mapping's url-pattern pointed to the org.apache.jsp.welcome_jsp.welcome_jsp servlet with the short name welcome_jsp corresponding to login.htm action part here:
<form action="welcome_jsp" method="post">
If you run the application again, you'll get the same result.
To explain it further, the welcome_jsp actually extends org.apache.jasper.runtime.HttpJspBase
So the welcome_jsp is indeed a Servlet and it's generated from welcome.jsp by the Eclipse environment.
Summary
In this short tutorial, we introduced the Integrated Java Web Development environment with Eclipse and how to develop, test, and configure a web application. We are ready to move to the next in upcoming articles.
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.