如何在Java开发用的Eclipse(含Photon版)中开发JSP网站?
How to Add JSP Development Support to Eclipse Photon (Pure Java Edition)
Hey there! Since you're already using Eclipse Photon for pure Java work, adding JSP support is straightforward—no need to switch to a different IDE. Let's walk through the steps to get you set up:
Step 1: Install the Eclipse Web Tools Platform (WTP) Plugin
Your pure Java Eclipse Photon doesn't include web development tools out of the box, so we'll install the WTP plugin first:
- Open Eclipse, go to
Help>Install New Software. - In the "Work with" dropdown, select the Photon official update site (it’ll look like
Photon - https://download.eclipse.org/releases/photon; if it’s not listed, paste that URL directly). - Expand the Web, XML, Java EE and OSGi Enterprise Development category.
- Check these core components (you can pick more if you need extra features, but these are the essentials for JSP):
- Eclipse Java EE Developer Tools
- Eclipse Web Developer Tools
- JSP Development Tools
- Click
Next, review the installation details, accept the license agreements, and proceed. - Restart Eclipse when prompted—this is crucial for the changes to take effect.
Step 2: Create a Dynamic Web Project
With the web tools installed, create a project tailored for JSP development:
- Go to
File>New>Project, search for and select Dynamic Web Project. - Enter a project name, then click
Next. - On the next screen, you’ll need a Target Runtime (your web server, like Apache Tomcat). If you haven’t set one up yet, click
New Runtime(we’ll cover that in Step 3). - Keep most default settings, but if you need a traditional
web.xmldeployment descriptor, make sure to check that box before clickingFinish.
Step 3: Configure a Web Server (e.g., Apache Tomcat)
To run your JSP project, you need a web server configured in Eclipse:
- Go to
Window>Show View>Servers(if the Servers view is missing, switch to the Java EE perspective viaWindow>Perspective>Open Perspective>Other>Java EE). - Click the link that says No servers are available. Click this link to create a new server....
- Select Apache > Tomcat v8.5 Server (or v9.0, which works perfectly with Eclipse Photon) and click
Next. - Browse to your local Tomcat installation directory, then click
Finish. - Add your project to the server: Right-click the server in the Servers view >
Add and Remove..., select your Dynamic Web Project, and clickFinish.
Step 4: Create and Edit JSP Files
Now you’re ready to write JSP code:
- In your project, navigate to the
WebContentfolder (this is the root of your web app). - Right-click
WebContent>New>JSP File. - Enter a filename (e.g.,
index.jsp) and clickFinish. - You can now mix HTML markup with Java code using JSP syntax. Here’s a quick example to get started:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>My First JSP</title> </head> <body> <h1>Hello from JSP!</h1> <% String dynamicMessage = "This comes from embedded Java code"; %> <p><%= dynamicMessage %></p> </body> </html>
Step 5: Run Your JSP Project
Test your application with these steps:
- Right-click your Dynamic Web Project >
Run As>Run on Server. - Select your configured Tomcat server and click
Finish. - Eclipse will start the server and open a browser window pointing to your app (usually at
http://localhost:8080/YourProjectName/index.jsp).
Quick Tips
- Stick to Tomcat 8.5 or 9.0 for the best compatibility with Eclipse Photon.
- If plugin installation fails, double-check your internet connection and ensure you’re using the correct Photon update site.
- The Java EE perspective organizes views like Servers and Project Explorer to make web development smoother.
内容的提问来源于stack exchange,提问作者Joel J Sebastian
相关产品推荐
相关产品推荐

