Deploy your application in Server:
Write the following sample code. //package a;
import java.io.*; import javax.servlet.*; import javax.servlet.http.*;
public class FirstServlet extends HttpServlet { protected void doGet(HttpServletRequest request , HttpServletResponse response)throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<body>"); out.println("This is my first SERVLET EVER"); out.println("</body> </html>"); out.close(); } }
Enter the entry for servlet file in web.xml
E.g., <servlet> <servlet-name>FirstServlet</servlet-name> <servlet-class>com.sample.FirstServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>FirstServlet</servlet-name> <url-pattern>/FirstServlet</url-pattern> </servlet-mapping>
deploy the application in two ways.
1. Manually create the .war file 2. write ant script to deploy
For Apache-Tomcat server application will be deployed on WebApps folder.
For JBoss application will be deployed on server/default/deploy/MyApp.war WAR directory structure: MyApp.war -- contains WEB-INF folder and .jsp files -- WEB-INF Contains classes folder, web.xml, lib folderRun on Browser:
Now Start your server.
Run your application on browser like http://localhost:8080/MyApp/login.jsp Otherwise you can run Directly a Servlet file.
http://localhost:8080/MyApp/FirstServlet
No comments:
Post a Comment