Notice: Undefined index: in /data/phpspider/phplib/misc.function.php on line 226
Java HTTP状态405-使用jsp时,此URL不支持HTTP方法GET_Java_Jsp_Servlets - Fatal编程技术网

Java HTTP状态405-使用jsp时,此URL不支持HTTP方法GET

Java HTTP状态405-使用jsp时,此URL不支持HTTP方法GET,java,jsp,servlets,Java,Jsp,Servlets,我试图通过表单从最终用户那里获取输入。我使用jsp制作表单 welcome.jsp <!DOCTYPE html> <html lang="en"> <head> <title>Welcome</title> </head> <body> <form action="welcome" method="post"> <input type="text" value

我试图通过表单从最终用户那里获取输入。我使用
jsp
制作表单

welcome.jsp

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Welcome</title>
</head>
<body>
     <form action="welcome" method="post">
        <input type="text" value="username" />
        <input type="text" value="password" />
        <input type="submit" value="login" />
     </form>
</body>
</html>
web.xml

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

<servlet>
    <servlet-name>MyApp</servlet-name>
    <servlet-class>main.com.myfirstapp.MyApp</servlet-class>
</servlet>
</web-app>

我已经遇到了同样的问题,我建议您从操作中删除斜杠,让它只是
,因为您使用的是@annotation,所以不需要web.xml,您可以删除它。 另一件事是,您无法在servlet中获得等待的结果,因为表单中没有名称,下面是一个示例 键入
String name=req.getParameter(“name”)
在表单中,您必须像这样设置名称而不是值
,对于最后的表单也是一样

<form action="welcome" method="post">
        <input type="text" name="name" />
        <input type="text" name="passcode" />
        <input type="submit" value="submit" />
</form>


“当我在服务器上执行我的程序时”这是一个关于在webbrowser中打开JSP页面的非常奇怪的描述。或者您是否在我的IDE中右键单击servlet类,选择option run on server orso?浏览器地址栏中的URL到底是什么?它是包含HTML表单的JSP之一,还是根本没有
doGet()方法的servlet之一?例如,您是否阅读了上一个问题的副本中链接的内容?在表单中,特别是在操作中,不要以“/”开头,让它“欢迎”,因为注释上已经有一个斜杠it@BalusC是的,我右键单击MyApp.java->在服务器上运行。浏览器中的URL为
http://localhost:8080/MyFirstApp/welcome
。我还通读了这个问题,并更新了我的问题。尽管如此,我仍然会遇到相同的错误。@PacMan我试过了,错误仍然存在。web inf文件夹是一个安全的文件夹,您不能在其中放置jsp文件(除非在某些框架中不是这样)你应该把它直接放在网络内容中,不要忘记改变你的形式,正如我在回答中所显示的那样。谢谢你的帮助,这很有帮助,因为我之前做错了。但我仍然遇到了错误,所以我查看了github上的其他servlet示例,幸运的是,我找到了一个使用
@WebServlet(name=“welcome”,value=“/”)
HTTP Status 405 - HTTP method GET is not supported by this URL
type: Status report
message: HTTP method GET is not supported by this URL
description:  The specified HTTP method is not allowed for the requested resource.
<form action="welcome" method="post">
        <input type="text" name="name" />
        <input type="text" name="passcode" />
        <input type="submit" value="submit" />
</form>