http状态404:找不到所需的资源 [英] http status 404 : the required resource is not found

查看:1612
本文介绍了http状态404:找不到所需的资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用eclipse和tomcat7创建了一个Web应用程序,我在html文件和java servlet类中有以下代码 在html文件中:

I creat a web application using eclipse and tomcat7 I had the following code in the html file and the java servlet class in the html file:

<form action="UserAccessServlet" method = "get">

在我拥有的servlet类中

in the servlet class I had

@WebServlet ("/UserAccessServlet")

然后,我做了一些小的更改(新的println语句),但是用下面的代码更改服务器名称没有效果

then I just made some small changes (new println statements) but it shows no effect I changed the server name with the following peice of code

html文件:<form action="SQA_Servlet" method = "get"> java类:@WebServlet ("/SQA_Servlet")

html file: <form action="SQA_Servlet" method = "get"> java class: @WebServlet ("/SQA_Servlet")

但是似乎没有重新加载发生,并且出现以下错误:

but it seems that no reload take place and I got the following error:

HTTP Status 404 - /SQA_Learning/SQA_Servlet

--------------------------------------------------------------------------------

type Status report

message /SQA_Learning/SQA_Servlet

description The requested resource (/SQA_Learning/SQA_Servlet) is not available.

我尝试清理模块,刷新,然后关闭并重新打开项目,结果相同

I tried clean the module, refresh, close the reopen the project with the same result

我将@WebServlet ("/SQA_Servlet")替换为@WebServlet(urlPatterns={"/SQA_Servlet"})

并且仍然没有效果..任何建议.

and still have no effect.. any suggestion.

推荐答案

我不确定何时以及在何种情况下收到此错误.但是,如果要部署到tomcat,则可能会发生以下情况:

I'm not sure when and in what for conditions you are receiving this error. But if you are deploying to tomcat, the following might occur:

假设您的Web应用程序名为"my.webapp",则导致my.webapp.war 假设您有一个执行action1 => @WebServlet(urlPatterns = "/action1")的Servlet"servlet1"(请注意action1前面的斜杠)

Assuming your webapp is called "my.webapp" resulting in my.webapp.war assuming you have a Servlet "servlet1" which performs action1 => @WebServlet(urlPatterns = "/action1") (note the slash in front of action1)

假设您正在以html格式调用此操作: <form action="/action1" method="GET">由于action1前面的斜杠,这可能不起作用

Assuming you are calling this action with a html form: <form action="/action1" method="GET"> this might not work because of the slash in front of action1

当它存在时,tomcat将重定向到localhost:8080/action1?. 而应该重定向到localhost:8080/my.project/action1?..

When it's there tomcat will redirect to localhost:8080/action1?.. while it should redirect to localhost:8080/my.project/action1?..

解决方案更改html,因此表单如下所示: <form action="action1" method="GET">,请勿更改@WebServlet(urlPatterns = "/action1")

Solution alter the html so the form looks like: <form action="action1" method="GET">, don't change the @WebServlet(urlPatterns = "/action1")

希望这对某人有帮助!

这篇关于http状态404:找不到所需的资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆