I am explaining every step to run tomcat in window and how to setup your projects and running Servlets.Install JDK before installing tomcat.I installed JDK1.6.0 on C:\Java\jdk1.6.0. Do not installed JDK under C:\Program Files. I just faced problem after setting my environment variable on Window Xp.
Download the latest version of tomcat. tomcat.apache.org , i downloaded Apache Tomcat 7.0.65.I rename downloaded folder to "apache-tomcat" and placed it at E:\apache-tomcat.Go to "Start" --> "My Computer" --> Right click--> "Property"--> Click "Advance Tab" --> "Environment Variables" --> Opens a window where you have to create new Environment Variables As Written Below
/* Under User Variable click New */ Variable Name CATALINA_HOME Variable Value E:\apache-tomcat , Press ok Variable Name JAVA_HOME Variable Value C:\Java\jdk1.6.0, Press ok Variable Name JAVA_HOME Variable Value C:\Java\jdk1.6.0, Press ok Variable Name PATH Variable Value C:\Java\jdk1.6.0\bin, Press ok // Under System Variable click New Variable Name CALSSPATH Variable Value C:\Java\jdk1.6.0\bin;E:\apache-tomcat\lib\servlet-api.jar, Press ok
Now We have to edit configuration files E:\apache-tomcat\conf folder. Restart your computer, After below steps configuration.
Open file context.xml find line/xml tag <Context> and replace by <Context reloadable="true"> <servlet>...</servlet> inside this tag find <param-value>false</param-value> and replace with <param-value>true</param-value> Open file tomcat-users.xml and placed below code inside<tomcat-users>...</tomcat-users> <role rolename="manager-gui"/> <role rolename="admin-gui"/> <user username="boy108zon" password="boy108zon" roles="manager-gui,admin-gui"/>
Lets create a new project. created a folder called store in E:\apache-tomcat\webapps\ , Create Structure under
store(Project Folder) ---> WEB-INF(DIR) --> classes(DIR) , web.xml (FILE) classes(DIR)-->HelloWorld.java (File)
Placed below xml code in web.xml created as above
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> <servlet> <servlet-name>HelloWorld</servlet-name> <servlet-class>HelloWorld</servlet-class> </servlet> <servlet-mapping> <servlet-name>HelloWorld</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> </web-app>
Open http://localhost:8080/ You can see Tomcat Statup Page , you can click on Mange App it will ask you to enter username and password , As you putted OR placed in tomcat-users.xml. Here you can see list of Application running or deploy. if you further check our created application also visible to this list , you can Start , Stop , Reload , Undeploy your application here. Click on start so that our created application can be start. That's all , Now open http://localhost:8080/store/ and you will see your HelloWorld Running.
That's all , Now open http://localhost:8080/store/ and you will see your HelloWorld Running.