Presentation is loading. Please wait.

Presentation is loading. Please wait.

Jsp. JBoss Many servers (like JBoss and Glassfish) are Tomcat servers. The file structures and format for deployment are the same. Where (in what server.

Similar presentations


Presentation on theme: "Jsp. JBoss Many servers (like JBoss and Glassfish) are Tomcat servers. The file structures and format for deployment are the same. Where (in what server."— Presentation transcript:

1 jsp

2 JBoss Many servers (like JBoss and Glassfish) are Tomcat servers. The file structures and format for deployment are the same. Where (in what server directory) files get deployed varies. These jsp examples were developed on JBoss

3 Webapps with only jsp Jsp are compiled and run as if they were servlets by tomcat, but you write only script code and the container does the rest. Jsp, css and html files will go at the root of the webapp and WEB-INF will contain just an empty web.xml: <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">

4 Here is my (jsp) samples directory

5 Creating/Running a jsp for JBoss (or Tomcat) Create a directory named MyGreeting Within the MyGreeting directory, create a subdirectory named WEB-INF (capitalization matters, so be precise, and that's a dash, not an underscore) MyGreeting | +-- HelloWorld.jsp (*) | +-- WEB-INF | +-- web.xml (*) (*) denotes a file Create a JSP file named MyGreeting/HelloWorld.jsp Add the following text to the HelloWorld.jsp file: Hello World! Create the web.xml file in MyGreeting/WEB-INF/web.xml Add the following text to web.xml: note – this xml doc is basically empty. (from code/Chapter1/MyGreeting/WEB-INF/web.xml)

6 deployment Put the directory into Tomcat webapps or create the war file. To build the war: Drop to a command line and change to the MyGreeting directory Use the command-line jar utility, jarring up any jsp files as well as the WEB-INF dir into a war called MyGreeting: c:\j2ee\code\Chapter1\MyGreeting> jar cvf MyGreeting.war *.jsp WEB-INF Note that to jar additional files like html or css you could use jar cvf MyGreeting.war *.jsp *.html *.css WEB-INF Or jar cvf MyGreeting.war *.* WEB-INF Copy MyGreeting.war to the deploy folder in your JBoss installation (or to webapps in tomcat): c:\j2ee\code\Chapter1\MyGreeting> copy MyGreeting.war c:\j2ee\jboss\deploy\ Start JBoss Open a web browser and go to http://localhost:8080/MyGreeting/HelloWorld.jsp

7 A very simple JBoss example

8 url for a similar JBoss example using jsp http://www.centerkey.com/jboss/ 1) Create Work Folder Create a folder called "HelloWorld" separate from your JBoss installation. For example, the full path of your work folder could be "C:\Projects\HelloWorld".

9 2) Create Startup Script below (or just navigate to the bin directory and click the run batch file) In the "HelloWorld" folder create a file named "JBoss.bat" with the following content: JBoss.bat @echo off set JAVA_HOME=\Program Files\Java\jdk1.6.0_11 set JBossHome=\Apps\JBoss\jboss-5.0.0.GA set Path=%JAVA_HOME%\bin;%Path% cd "%JBossHome%\bin" run.bat

10 Write JSP File hi.jsp in the "HelloWorld“ dir This JSP simply displays a greeting along with the current date and time. JSP Test

11 Create Deployment Descriptor In the "HelloWorld" folder, create a sub folder called "WEB-INF", and in that folder create a file named "web.xml" as: web.xml Hello World The deployment descriptor provides information to JBoss about your web application.

12 Create WAR Builder & Deployer In the "HelloWorld" folder, create a file called "Deploy.bat" as: Deploy.bat @echo off set JAVA_HOME=\Program Files\Java\jdk1.6.0_11 set JBossHome=\Apps\JBoss\jboss-5.0.0.GA "%JAVA_HOME%\bin\jar.exe" -cvf helloworld.war *.jsp WEB- INF copy helloworld.war "%JBossHome%\server\default\deploy" pause This script uses Java's JAR utility to zip up the appropriate contents into a WAR file.

13 Test Your Web Page Run the "Deploy.bat" file. In a browser, open "http://localhost:8080/helloworld/hi.jsp" to see your web application run.http://localhost:8080/helloworld/hi.jsp

14 A jsp with parameter

15 The order jsp, xml… <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/j2ee/dtds/web -app_2_2.dtd"> Order Confirmation <LINK REL=STYLESHEET HREF="JSP-Styles.css" TYPE="text/css"> Order Confirmation Thanks for ordering !

16 Css for this example BODY { background-color: #FDF5E6 } A:hover { color: red } H1 { color: #440000; text-align: center; font-family: Arial Black, Arial, Helvetica, sans-serif } H2 { color: #440000; font-family: Arial, Helvetica, sans-serif } H3 { color: #440000; font-family: Arial, Helvetica, sans-serif } UL { margin-top: 0; border-top-width: 0; padding-top: 0 } DT { font-weight: bold; } PRE { font-size: 105%; } CODE { font-size: 105%; }.TOC { font-size: 90%; font-weight: bold; font-family: Arial, Helvetica, sans-serif } TH.COLORED { background-color: #FFAD00 } TR.COLORED { background-color: #FFAD00 } TH.TITLE { background-color: #EF8429; font-size: 28px; font-family: Arial, Helvetica, sans-serif; } Remember to build directory structure with web-inf containing web.xml and jsp and css at top level. Jar into a war file and deploy in JBoss default server.

17 A bunch of jsp from the coreservlets text Along with an empty web.xml file, the css file from above, I packaged a bunch of the simple jsp examples from coreservlets as a war file and put them in JBoss. An example shown below.


Download ppt "Jsp. JBoss Many servers (like JBoss and Glassfish) are Tomcat servers. The file structures and format for deployment are the same. Where (in what server."

Similar presentations


Ads by Google