How to run simple JSP program


First you have to put your JSP file into the container's folder. The folder must contains a sub folder named "WEB-INF".

For an example, if we use Apache Tomcat (assume Tomcat installed to C:\Tomcat directory), you have to put your jsp file into a subfolder of C:\Tomcat\webapp folder.

Assume, your jsp file is "index.jsp"; in this case, you have to put it as:
C:\Tomcat\webapp\MyName\index.jsp

And, there should be another sub folder named "WEB-INF" as:
C:\Tomcat\webapp\MyName\WEB-INF
(However, this folder can be empty)

After that, you have to restart your web server (this is vendor specific), and you can see the output via the browser.

By default, many J2EE web servers uses 8080 port for the client access. In this case, you can see the output on your local machine by typing the following address on your browser's address bar:

http://localhost:8080/MyName

--------------------------------------...


Sample program for index.jsp
======================



<% String myName="krish"; out.println(myName); %>
<%=myName%>




The output should be:
krish krish

More info

Under the Tomcat root directory there will be a sub-directory named web-apps, all web applications running on this Tomcat server will reside there. Each web application will have it's own sub-directory under web-apps, so you could create a directory for your web application under the web-apps directory like so /web-apps/. JSP pages can be placed insisde the directory you have created or in other sub-directories you might like to create, however please note that for each new sub-directory you place your JSP files in the URL to access them will need to include each directory.

Inside the directory you created there needs to be another directory named WEB-INF, this directory will contain the web.xml file which contains configuration information for your web application such as the welcome file for your application, all servlet mappings, filters, etc...

Under the WEB-INF directory you can create another directory named classes, all your java classes used in your web application should be placed in here, in a tree structure that resembles their packages, for example: if you have a class named MyClass whose package is com.xyz then the class should be placed in /web-apps//WEB-INF/classes/com/xyz/MyClass.class. Another alternative to handling classes in this way is to package them all in a jar file, the jar file can be placed in a directory named lib also under the WEB-INF directory, for example: say you have a jar file named myLibrary.jar, it can be placed in /web-apps//WEB-INF/lib/myLibrary.jar. By placing classes and jar files in these directories Tomcat ensures they are on the CLASSPATH when you run your application.

An alternative to repeating this procedure each time you want to deploy some JSP pages to your Tomcat server is to simply create a WAR file and use the Tomcat manager (which can be accessed through a browser window) to deploy the WAR file to the server


0 comments:

Post a Comment