-
1. Re: JSP/Servlet .war/.ear example needed.
coolerking Sep 13, 2005 4:40 AM (in response to coolerking)managed to figure this out. Included below is a simple example that you can try out yourself:
---------------------------------------------------------------------------------------------------------
Simple example to create a JSP page calling a Servlet and deploy the .war (or .ear) in JBoss
----------------------------------------------------------------------------------------------------------
1) create the foll directory structure:
/example2/WEB-INF/classes
2) store the files as follows
JSP File: /example2/index.jsp
Servlet File: /example2/WEB-INF/classes/HelloWorld.class
(compile the servet HelloWorld.java and store the class file)
web.xml: /example2/WEB-INF/web.xml
application.xml: /META-INF/application.xml
3) In JSP file, reference the Servlet as:<a href="/example2/Servlet/HelloWorld/>
4) web.xml file<?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>/servlet/HelloWorld</url-pattern> </servlet-mapping> </web-app>
5) application.xml file
<?xml version="1.0" encoding="ISO-8859-1"?> <application> <display-name>Example 2</display-name> <module> <web> <web-uri>example2.war</web-uri> <context-root>/example2</context-root> </web> </module> </application>
6) Create a .war file with the *contents* of example2 folder:
cd c:\example2
jar -cvf example2.war *
(Same thing can be done using winzip, but **enter example2 directory** and zip the contents to example2.war)
7) jar /META-INF/ + example2.war = example2.ear
8) Deploy example2.ear in /server/default/deploy directory OR skip #7 and deploy the example2.war directly into the deploy directory
9)
http://localhost:8080/example2/index.jsp ---> JSP page
http://localhost:8080/example2/servlet/HelloWorld ------> Servlet
Note to access URLs:
-------------------
The URL to access the JSP page will be:
http://localhost:8080/<.war_package_name/>/page.jsp
To access the Servlet, simply append the <url-pattern> defined for the Servlet like this:
http://localhost:8080/<.war_package_name/>/**<url-pattern_for_servlet>**
Deploying the .ear file instead of the .war has no bearing on the URLS.