this code sent get request, why?
<form th:action="#{/books/edit/rename}" th:object="${book}" th:method="POST">
<input type="text" id="id" name="id" th:value="*{id}" value="1"/>
<input type="text" id="bookName" name="bookName" th:value="*{bookName}" value="nameExample"/>
<button type="submit">Rename for model</button>
</form>
Try removing the th: in the method declaration, to be as the following:
<form th:action="#{/books/edit/rename}" th:object="${book}" method="POST">
…
Because it is not reading the code and the default is GET, check this for more details https://www.w3.org/TR/html401/interact/forms.html#h-17.3
Related
I'm trying to login a website (vimla.se) using Jsoup in android. I'm aware that when submitting forms in html, action is the attribute which we use to POST the login credentials using Jsoup (as explained here). However, in my case, there's no action pointer and the html form looks something like this:
<form id="loginForm" name="loginForm" ng-submit="login()" method="POST">
<input type="email" id="username" form-filler required="required" class="text txtEmail" name="username" placeholder="E-mail" autofocus="autofocus" ng-model="username" />
<br />
<input type="password" id="password" required="required" class="text txtPass" name="password" form-filler placeholder="Password" autofocus="autofocus" ng-model="password" />
<br />
<button type="submit" class="btn" ng-disabled="sending">Login</button>
</form>
So my question is, how do we login such forms using Jsoup?
This is actually a form using Angular.js. The action - attribute is not specified, but ng-submit https://docs.angularjs.org/api/ng/directive/ngSubmit
describes what to do on submit. The LoginController then implements the function that gets executed. Its implementation is hidden in https://vimla.se/scripts/all.min.js?v=1.0.0.0.
a.login=function(){a.sending||(a.sending=!0,a.error=!1,b.post("/user/login",{username:a.username,password:a.password,referer:a.referer})
So the url that gets called is /user/login and the parameters transmitted are username, password, referer
I have a problem with binding my object in ftl form.
Here is my controller method:
#RequestMapping(method = RequestMethod.POST)
public String saveConfigProperties(#ModelAttribute("configCmdList") ConfigCmdList configCmdList, BindingResult bindingResult) {
configurationDao.setConfigValues(configCmdList.getConfigurations());
return "config";
}
and here is part of my ftl:
<form action="" method="POST">
<#spring.bind "configCmdList" />
<#list configCmdList.configurations as config>
${config.name}
</#list>
<input type="submit" value="submit"/>
</form>
I have an access to my list of objects which I sent previous using GET method in my ftl, but my object list is null after sending object without modifications back to controller.
I tried to bind my configCmdList.configurations and also bind separately each element of that list in loop but without success.
What I'm missing?
VairalPatel web page is down and I remember that he wrote good example about freemarker form and spring mvc.
Thanks in advance for your help.
Ok, I resolved an issue. I had to bind each list element and it parameters separately in loop using ${spring.status.expression} and ${spring.status.value}.
Here is my code:
<form action="" method="POST">
<#list configCmdList.configurations as config>
<#spring.bind path="configCmdList.configurations[${config_index}].id"/>
<input type="hidden" name="${spring.status.expression}" value="${spring.status.value}" />
<#spring.bind path="configCmdList.configurations[${config_index}].name"/>
<input type="text" name="${spring.status.expression}" value="${spring.status.value}" />
<#spring.bind path="configCmdList.configurations[${config_index}].value"/>
<input type="text" name="${spring.status.expression}" value="${spring.status.value}" />
</#list>
<input type="submit" value="submit"/>
</form>
Thank you for your help :)
This is another way to write Caro's solution:
<form action="" method="POST">
<#list configCmdList.configurations as config>
<input type="hidden" name="configurations[${config_index}].id" value="${config.id}"/>
<input type="text" name="configurations[${config_index}].name" value="${config.name}"/>
<input type="text" name="configurations[${config_index}].value" value="${config.value}" />
</#list>
<input type="submit" value="submit"/>
</form>
Hi I have the following function:
<script type="text/javascript" src="clientscript/vbulletin_md5.js?v=387"></script>
<form action="login.php?do=login" method="post" onsubmit="md5hash(vb_login_password, vb_login_md5password, vb_login_md5password_utf, 0)">
<input type="hidden" name="s" value="" />
<input type="hidden" name="do" value="login" />
<input type="hidden" name="vb_login_password" />
<input type="hidden" name="vb_login_md5password" />
<input type="hidden" name="vb_login_md5password_utf" />
<table cellpadding="0" cellspacing="3" border="0">
<tr>
Unfortunately the function has no id or name etc. How is it possible to click on the Javascript button and get back the result? Thanks for all your answers in advance.
Use as below
onsubmit="return md5hash(vb_login_password, vb_login_md5password, vb_login_md5password_utf, 0)"
And define md5hash into Javascript with ture/false value
HTML Page
<form action="viewParticularImage.jsp" method="post">
input type="submit" name="1" value="Details" />
input type="submit" name="2" value="Details" />
input type="submit" name="3" value="Details" />
</from>
JSP page
<%
String name = request.getParameter("name");
out.write(name);
%>
i am getting null value in name while printing the button Details in JSP Page pls help to find the solution, thanks to the replies in advance .
You have parameters named as "1", "2" and "3", but you have not parameter named as "name".
<form action="viewParticularImage.jsp" method="post">
<input type="submit" name="name" value="Details" />
...
</from>
In your JSP page make it
<%
String name = request.getParameter("1");
out.write(name);
%>
You are not sending a parameter named name in the request.That's why! To confirm, try
<%
String name = request.getParameter("1");
out.write(name);
%>
Your form should be like below. See the value of name attribute of the input text. The name attribute denotes the name of the request parameter
<form action="viewParticularImage.jsp" method="post">
First name: <input type="text" name="name"><br>
<input type="submit" value="Submit">
</form>
Note : Try entering a value in the text and submit. You will receive it in the server request
I believe you haven't gained any knowledge regarding HTML ... First, go and check the tutorials regarding HTML...
Let's get to the game ... What are you trying to do ... Are you trying to pull down values set to the submit button ... or you are trying to publish a textfield where user can type their name and show that name as the result in the next page ????
If you are trying to publish the values assigned to the submit button...
HTML Page
<form action="viewParticularImage.jsp" method="post">
<input type="submit" name="1" value="Details" />
<input type="submit" name="2" value="Details" />
<input type="submit" name="3" value="Details" />
</form>
JSP page
<%
String name = request.getParameter("1");
out.write(name);
%>
If you are trying to publish what users type ...
HTML Page
<form action="viewParticularImage.jsp" method="post">
<input type="text" name="name" />
<input type="submit" value="Hit Send" />
</form>
JSP page
<%
String name = request.getParameter("name");
out.write(name);
%>
I think this clarifies you how things work !!!! Thank you ... peace !!!
I have the following code that prints some links on the page, and is supposed to call a controller method (launch), upon clicking the image. However, I am getting an Error 400 when I click the button. The generated links look correct to me. The code is in the 1st block. The actual View-Source is in the 2nd.
Unfortunately, I am not getting any errors in my server logs, so I don't know where to begin to debug this.
Does anyone see anything wrong with my code.
<div id="links">
<ul>
<c:forEach items="${listAppURLForm}" var="appURLForm">
<li>
<h2>${appURLForm.link}</h2>
<p>
<span>
<form method="post" action='<c:url value="launch"/>'>
<input type="hidden" name="id" value="${appURLForm.link}"/>
<input type="image" src='<c:url value="/images/rocket-thumbnail.png"/>'/>
</form>
</span>
</p>
</li>
</c:forEach>
</ul>
</div>
The rendered page:
<form method="post" action='launch;jsessionid=40d63cd386e5d01ef8c6dc1c1b76'>
<input type="hidden" name="id" value="http://www.cnn.com"/>
<input type="image" src='/services/images/rocket-thumbnail.png;jsessionid=40d63cd386e5d01ef8c6dc1c1b76'/>
</form>
400 means server cant understand what browser sent
your action='launch;jsessionid=40d63cd386e5d01ef8c6dc1c1b76' might be ?launch;jsessionid=40d63cd386e5d01ef8c6dc1c1b76
<form method="post" action='?launch;jsessionid=40d63cd386e5d01ef8c6dc1c1b76'>
<input type="hidden" name="id" value="http://www.cnn.com"/>
<input type="image" src='/services/images/rocket-thumbnail.png;jsessionid=40d63cd386e5d01ef8c6dc1c1b76'/>
</form>