Jakarta EE Programming/Jakarta Server Pages
Appearance
(Redirected from JSP)
Here is a minimalist tutorial to create a JSP using Eclipse.
- If you have not already installed Eclipse, read this page.
- If you have not already installed an application server, read this page.
- Launch Eclipse
- On the Project Explorer view, right-click and select New -> Other...
- Select Web -> Dynamic Web project .
- Type helloworld for the Project name.
- On Target runtime, make sure that you have selected your application server instance.
- Click on Finish .
- Double-click on your new project to open it.
- Right-click on the folder WebContent .
- Select New -> JSP File .
- On File name, type
FirstPage.jsp
. It will be the name of your JSP. - Click on Finish . The new
FirstPage.jsp
file should appear in the folder WebContent . - Locate the text
<body>
in the new JSP file. - After this text, write
Hello World!
. - Right-click on the folder WebContent/WEB-INF .
- Select New -> File .
- On File name, type
web.xml
. This file is used to link our JSP with a URL in order to access to it. It can map many other things. - Click on Finish .
- Double-click on the new file to open it.
- In the file, write the following content:
<?xml version="1.0" encoding="ISO-8859-1" ?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> <servlet> <servlet-name>firstpage</servlet-name> <jsp-file>/FirstPage.jsp</jsp-file> </servlet> <servlet-mapping> <servlet-name>firstpage</servlet-name> <url-pattern>/firstpage</url-pattern> </servlet-mapping> </web-app>
- Right-click on the project.
- Select Export -> WAR file . If you don't find the option WAR file, click on Export... instead, select Web -> WAR file and click on Next >. The web project should be named
helloworld
. - Choose a location for the destination. It's the folder where your application containing your JSP will be created. Remember this location.
- Click on Finish .
- Go on the folder where you have created your application. You should see a file named
helloworld.war
. - Copy/paste your WAR file in the deployment folder of your application server.
- Start your application server.
- On a browser, go on
http://localhost:8080/helloworld/firstpage
. You should see "Hello World!".
On the URL, helloworld comes from the name of the WAR file we have created and firstpage comes from the markup <url-pattern>
in the web.xml
file.