[英]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.class
和HelloWorldForm.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.jar
和servlet-api.jar
到Java构建路径( Eclipse
库”部分)。 It solved my 404 problem. 它解决了我的404问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.