Eclipse Mars中Tomcat v8.0启动异常及JSP相关问题求助
Hey, let's tackle your issues one by one— I've run into similar headaches with Eclipse Mars and Tomcat before, so here's how to fix them step by step:
The core error here is that your web application context (/LoginModule) failed to start, which is taking the whole server down. Let's address this:
Check your Servlet configuration
Make sure yourLogin.javaServlet is properly set up:- Move
Login.javainto a dedicated package (e.g.,com.yourname.servlet) instead of leaving it in the root of yoursrcdirectory. Tomcat requires Servlets to be in a package to load them correctly. - Verify your
web.xmlhas the correct full class path for the Servlet. For example:
Double-check for typos in the package or class name— even a small mistake will break the context startup.<servlet> <servlet-name>LoginServlet</servlet-name> <servlet-class>com.yourname.servlet.Login</servlet-class> </servlet> <servlet-mapping> <servlet-name>LoginServlet</servlet-name> <url-pattern>/login</url-pattern> </servlet-mapping>
- Move
Clean Tomcat's working directories
Corrupted cached files often cause startup failures:- Right-click your Tomcat server in Eclipse → Clean... → Select "Clean Tomcat Work Directory".
- Manually delete the
workfolder in your Tomcat installation directory (C:\Program Files\Apache Tomcat 8.0.48\work). - Also delete the temporary server files in your Eclipse workspace: navigate to
.metadata/.plugins/org.eclipse.wst.server.core/tmp0(or the folder matching your Tomcat instance) and delete its contents.
Verify port settings
Even though you're using 8081 for HTTP, Tomcat's shutdown port (8005) might be occupied. Open your Tomcat'sserver.xmland change the shutdown port to something else, like 8015:<Server port="8015" shutdown="SHUTDOWN">Confirm JDK compatibility
Tomcat 8.0 requires JDK 7 or higher (you're using JDK 8, which is fine), but make sure Eclipse is using the correct JRE for Tomcat:
Right-click your Tomcat server → Properties → Runtime Environment → Selectjdk1.8.0_151from the list.
When the server starts but throws a 404, it usually means your project isn't deployed correctly or you're using the wrong URL:
Ensure your project is added to the server
Right-click your Tomcat server → Add and Remove... → Select yourLoginModuleproject and move it to the "Configured" side, then click Finish.Use the full deployment URL
When using workspace metadata, your project is deployed under its context root. So instead of visitinghttp://localhost:8081/login.jsp, you need to usehttp://localhost:8081/LoginModule/login.jsp(replaceLoginModulewith your project's actual context root if you changed it).Clean and redeploy
Right-click your project → Run As → Clean..., then right-click the Tomcat server → Publish. Restart the server after this.
For the missing syntax coloring and formatting resets:
Use the correct editor
Right-click your JSP files → Open With → JSP Editor (not Text Editor or HTML Editor). This ensures Eclipse applies JSP-specific syntax highlighting.Enable syntax highlighting in preferences
Go to Window → Preferences → Web → JSP Files → Editor. Make sure "Enable syntax highlighting" is checked, and adjust the color settings if needed.Fix persistent formatting problems
- When formatting, use the JSP-specific formatter: Right-click the JSP file → Source → Format (or Ctrl+Shift+F). If a dialog pops up, select the HTML/JSP formatting profile.
- Check your project's file encoding: Right-click the project → Properties → Resource → Text file encoding. Set it to match your JSP's
pageEncoding(ISO-8859-1, or switch to UTF-8 for better compatibility). - Disable unnecessary builders: Go to Project → Properties → Builders and remove any third-party or unused builders that might be overwriting your formatted files.
内容的提问来源于stack exchange,提问作者mike

