一般的form表单提交方式要么是get要么是post,我打算自己在servlet里面写自定义的函数,比如login()函数,而不去实现dopost和doget方法,这样我form表单提交的时候加一个hidden参数method=login,于是运行的时候就一直报405method not allowed的错误,下面提示“HTTP method POST is not supported by this URL”
<form class="form-horizontal" method="post" action="${pageContext.request.contextPath }/user">
<input type="hidden" name="method" value="login">
<div class="form-group">
<label for="username" class="col-sm-2 control-label">用户名</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="username" name="username"
placeholder="请输入用户名">
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">密码</label>
<div class="col-sm-6">
<input type="password" class="form-control" id="inputPassword3" name="password"
placeholder="请输入密码">
</div>
</div>
jsp的表单代码
你把 servlet 的 method 与 HTML form 的 method(即 HTTP method) 混淆了,它们并没有直接的关系。
而且 HTML form 的 method 属性值只能是 get 或 post。
要实现自定义 HTTP method "LOGIN",你要在 servlet 添加处理 HTTP LOGIN method 的逻辑,如
这时不能使用 HTML form 测试,应该使用接口测试工具,发送类似下面的请求
譬如