Crating First Servlet Application(Using Notepad)
Server-Tomcat Apache
Step1:Install jar file of Tomcat apache and save it anywhere.
Step2:Extract using winrar .
Step3:SetUp system Environment Variables:
a)var name-CATALINA_HOME
value-Address of Tomcat apache before bin folder.
b)var name-JAVA HOME
value-Address of jdk
c)var name-JRE_HOME
value-Address of jre
d) var name-CLASSPATH
value-address of servlet-api(eg. D:\apache-tomcat-9.0.0.M4\lib\servlet-api.jar)
Check if apache works???
Goto-->tomcat-->bin-->shift+rightclick-->open command window here-->type startup.bat-->see(startup in x seconds in new window)
Step4:create file structure as follow:
Step5:create a .java file using notepad and edit it as follow
///servlet class must be public
import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;
public class FirstServlet extends HttpServlet{
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException
{
PrintWriter out=response.getWriter(); //provide location where to write
out.println("hello");
}
}
step 6:Save it.
Step7:compile it with follw to save its .class file to classes folder.
javac -d ../WEB-INF/classes FirstServlet.java.
CODE WILL COMPILE SUCCESSFULLY AND THE >CLASS FILE SAVE TO classes FOLDER.
Step 8:Create web.xml file as follow.
Save it in WEB-INF folder.
Step 9:deploy the servlet project
Copy the project and paste it under WEBAPPS folder
Step 9:start the server
Step 10:type into browser to run as:
http://hostname:portno/projectfile name/urlpatternofservlet
Step2:Extract using winrar .
Step3:SetUp system Environment Variables:
a)var name-CATALINA_HOME
value-Address of Tomcat apache before bin folder.
b)var name-JAVA HOME
value-Address of jdk
c)var name-JRE_HOME
value-Address of jre
d) var name-CLASSPATH
value-address of servlet-api(eg. D:\apache-tomcat-9.0.0.M4\lib\servlet-api.jar)
Check if apache works???
Goto-->tomcat-->bin-->shift+rightclick-->open command window here-->type startup.bat-->see(startup in x seconds in new window)
Step4:create file structure as follow:
Step5:create a .java file using notepad and edit it as follow
///servlet class must be public
import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;
public class FirstServlet extends HttpServlet{
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException
{
PrintWriter out=response.getWriter(); //provide location where to write
out.println("hello");
}
}
step 6:Save it.
Step7:compile it with follw to save its .class file to classes folder.
javac -d ../WEB-INF/classes FirstServlet.java.
CODE WILL COMPILE SUCCESSFULLY AND THE >CLASS FILE SAVE TO classes FOLDER.
Step 8:Create web.xml file as follow.
Save it in WEB-INF folder.
Step 9:deploy the servlet project
Copy the project and paste it under WEBAPPS folder
Step 9:start the server
Step 10:type into browser to run as:
http://hostname:portno/projectfile name/urlpatternofservlet



0 comments:
Post a Comment