Reputation: 3
I've got a form that I use to post some inputs to one site but I want to post them also to my servlet - is it even possible?
I've tried to do something with submit button, I mean executing onclick with function but something is not working properly
<input type="submit" value="value1" onclick="afterSubmit()"/>
...some inputs...
</form>
form=document.getElementById("${initParam['posturl']}";
function afterSubmit() {
form.action="http://localhost:8080/url/servlet";
}
</script>
And my servlet:
public class sendThis extends HttpServlet {
public void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
out.println(request.getParameter("item_name_1"));
}
}```
So when I click on submit button and then go to localhost:8080/url/servlet, I get this error:
HTTP Status 405 – Method Not Allowed
Type Status Report
Message HTTP method GET is not supported by this URL
Description The method received in the request-line is known by the origin server but not supported by the target resource.
Upvotes: 0
Views: 55
Reputation: 552
Add doGet method to your servlet and handle the request:
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
out.println(request.getParameter("item_name_1"));
}
Upvotes: 1