简体   繁体   English

在Eclipse中在Tomcat上使用Struts运行Web应用程序时出现404错误

[英]404 error while running web-app using Struts on tomcat in Eclipse

I am a beginner to web development using struts. 我是使用struts进行Web开发的初学者。 I have followed an online tutorial into making a web-app using Struts in Eclipse. 我已经按照在线教程学习了如何在Eclipse中使用Struts制作Web应用程序。 The link of the tutorial is http://www.dzone.com/tutorials/java/struts/struts-tutorial/struts-tutorial-using-eclipse-1.html where the source code is available. 本教程的链接是http://www.dzone.com/tutorials/java/struts/struts-tutorial/struts-tutorial-using-eclipse-1.html ,其中提供了源代码。 When i start the server and run the application , i get 404 page not found error despite i feel like i have done things properly. 当我启动服务器并运行应用程序时,尽管我觉得自己做得正确,但是却得到404页面未找到错误。 I have attached the error page i get. 我已附上我得到的错误页面。 在此处输入图片说明

Also I have checked logs for errors, but it doesn't give me any information apart from this 我也检查了日志中是否有错误,但是除此之外,它没有给我任何信息 在此处输入图片说明

So can anyone please help me find out why isn't the app working? 所以有人可以帮我找出为什么该应用程序无法正常工作吗?

struts-config file struts-config文件 在此处输入图片说明

Remove HelloWorlAction.class and HelloWorldForm.class . 删除HelloWorlAction.classHelloWorldForm.class

In struts you just need an action class and form class with a java extension. 在struts中,您只需要一个带有Java扩展名的action类和form类。

So you only need: 因此,您只需要:

HelloWorlAction.java
HelloWorlActionForm.java

You are getting errors 404 if you use /HelloWorld in the context path of your application. 如果在应用程序的上下文路径中使用/HelloWorld ,则会收到错误404。 Either you have deployed to the wrong path or this path doesn't exist. 您已部署到错误的路径,或者该路径不存在。 Try to remove it from the URL. 尝试将其从URL中删除。 Also in the tutorial you have mentioned it's not used. 另外,在教程中您已经提到它未被使用。 The url 网址

http://localhost:8080/StrutsExample1/helloWorld.do

I suggest you to start again calling your project "StrutsExample1" and leaving please WebContent as it is. 我建议您再次开始调用项目“ StrutsExample1”,并保持WebContent不变。 Follow strictly that tutorial and you will get what you're expecting. 严格按照该教程进行操作,您将获得期望的结果。

After doing that please use the correct path as suggested by Roman C: 完成此操作后,请使用罗马C建议的正确路径:

http://localhost:8080/StrutsExample1/helloWorld.do

Also you could use this header in web.xml: 您也可以在web.xml中使用此标头:

<?xml version="1.0" encoding="UTF-8"?>
<web-app    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns="http://java.sun.com/xml/ns/javaee"
            xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
            xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
            id="WebApp_ID" version="3.0">

if you are using modern containers as Tomcat 7. Let me know, regards 如果您正在使用现代容器作为Tomcat 7。

Try adding apache-commons.jar and servlet-api.jar to your Java build path (Libraries section in Eclipse ). 尝试将apache-commons.jarservlet-api.jar到Java构建路径( Eclipse库”部分)。 It solved my 404 problem. 它解决了我的404问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 带有tomcat,struts2和eclipse的Java Web应用程序上的404错误 - 404 error on java web app with tomcat, struts2, and eclipse 在 Eclipse 中的 Tomcat 7 上运行 Jersey Web 应用程序时出现 404 错误 - 404 error when running Jersey web app on Tomcat 7 in Eclipse 在Tomcat中部署的Web-app使用SocketHubAppender - Using a SocketHubAppender for web-app deployed in Tomcat 在Eclipse上运行动态Web项目会在Tomcat 7中引发404错误 - Running dynamic web projects on Eclipse brings up a 404 error in Tomcat 7 使用 Tomcat 部署 Eclipse Web 应用程序:提供多个项目的依赖项? - Eclipse Web-App Deployment with Tomcat: Providing multiple projects' dependencies? 在MySQL中使用Struts 2和Eclipse进行Hibernate编译时,App在Tomcat上显示404错误 - App gives 404 error on Tomcat when compiled in MySQL with Struts 2 and Hibernate on Eclipse Eclipse:Web服务:使用Tomcat7的404错误 - Eclipse: Web services: 404 error using Tomcat7 Eclipse 显示在使用 tomcat v9 运行 Web 应用程序时端口正在使用中,即使我更改了它 - Eclipse shows ports are in use while running a web app using tomcat v9 even when i change it 在eclipse上运行tomcat时出现404错误 - 404 error when running tomcat on eclipse REST Web服务404错误-Tomcat Eclipse - Rest Web service 404 error - Tomcat Eclipse
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM