Wednesday, December 12, 2012

First Dynamic Web Project

 THE FIRST DYNAMIC WEB APPLICATION PROJECT WITH ECLIPSE AND TOMCAT

    You can develop dynamic content web projects with tomcat. This example illustrates the opening dynamic web project and the important folders and files. First of all we installed tomcat to eclipse before and now we will create a new dynamic web project.
    First of all open your eclipse and click to FileàNewàDynamic Web Project. If there is not a Dynamic Web Project on the tab you can select other and find dynamic web project in there.
Picture 1
Picture 2
    There will be some folders such as in picture 3. As you can see in picture 3, there is a java resources file into the main folder root. The src folder in this folder will contain your java files such as servlets, beans, pojos, db classes etc... and near the src folder there will be a library which is Libraries that will contain JRE system libraries that your project will work on. As an example if your project will work on Java 1.5 this folder will contain Java 1.5 related jars. 


    The other important Folder is WebContent folder that will contain your front end files such as jsp, html... there is one folder that is specialized as WEB-INF, which contains unreachable files according to user. If you notice that i selected the Generate web.xml file while i was opening the project. This creates our projects web.xml file into the WEB-INF folder. This contains the project contents. Important from the point of project working structure. Web.xml will be defined later. Also there is a lib folder that can contain your external utilities.

    Now lets create an hello.jsp into the WebContent folder.(Right click on this folder and choose new Jsp)
Picture 3
There will be default codes such as
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

</body>
</html>
You will customize the codes according to your needs. Now only change the Insert title here to Hello
And add Hello between the <body> and </body> tags.

And add to your tomcat such as in picture 4. You can right click to your tomcat in the server tab and then click to Add and Remove then add your project. And then you can start your server with right click then start.It will deploy your project. After starting successfully open a browser then type
http:/{Your Project Name}/{Folders if there is/}your page
then you can see your result page such as in Picture 5 but if you can not see anythink you should check your server installation or there can be a problem about deploying your project.
Picture 4
Picture 5





No comments:

Post a Comment