LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Blogs > prayag_pjs
User Name
Password

Notices

Rate this Entry

Deploying Web Applications to Tomcat

Posted 09-16-2010 at 05:50 AM by prayag_pjs
Updated 09-16-2010 at 06:10 AM by prayag_pjs

After Installing tomact to Deploying Web Applications to Tomcat follow these steps :

Code:
cd $CATALINA_HOME/webapps
sudo mkdir -p application/WEB-INF/classes
sudo mkdir -p application/WEB-INF/lib
Code:
cd $CATALINA_HOME/webapps/application

sudo vim HelloWorld.java
// Filename : HelloWorld.java
// Description : This servlet merely says hello!
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloWorld extends HttpServlet {
        public void doGet ( HttpServletRequest request, HttpServletResponse response )
        throws ServletException, IOException    {
                response.setContentType("text/html");
                PrintWriter out = response.getWriter();
                out.println("<html>");
                out.println("<head><title>Hello, Cruel World!</title></head>");
                out.println("<body>");
                out.println("<h1>Hello,Cruel World!
</h1>");
                out.println("This is my first servlet.");
                out.println("</body>");
        }// end doGet

}///:~
Code:
sudo javac -classpath $CATALINA_HOME/common/lib/ servlet-api. jar HelloWorld.java
it will create HelloWorld.class

Code:
sudo mv HelloWorld.class WEB-INF/classes/
Code:
cd WEB-INF

sudo vim web.xml
<?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>/HelloWorld</url-pattern>
</servlet-mapping>

</web-app>
Code:
cd $CATALINA_HOME/bin
sudo ./shutdown.sh
sudo ./startup.sh
(it should display Hello, Cruel World !
This is my first servlet)
Deploying Java Server Pages.

Code:
cd $CATALINA_HOME/webapps/application
sudo vim index.jsp

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Hello JSP World!</title>
</head>
<body>
<h1>Hello, JSP World!</h1>

<p>
The time now is : <%= new java.util.Date() %>. 
</p>

<p>
To see the servlet example <a href="HelloWorld">click here</a>.
</p>

</body>
</html>
</programlisting>
Code:
sudo ./shutdown.sh 
sudo ./startup.sh
Posted in WebServers
Views 491 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 03:54 AM.

Main Menu
Advertisement

My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration