Jsp Action Form - servlets

Here is the jsp code:
<form name="loginForm" action="<%=formUrl%>" autocomplete="off" method="POST" >
...
</form>
What does <%=formUrl%> mean?Is it refers to servlet name? I dont have servlet named formUrl.

Related

pass value attribute from view to controller asp.net mvc

here was my code from view
#{ var companies = (IEnumerable<Company>)ViewData["companylist"]; }
#foreach (var item in companies)
{
//post the form to upload actions, index2 for testing
<form id="submitfinal" method="post" asp-action="Upload" asp-controller="report" enctype="multipart/form-data">
<input type="hidden" name="companyid" value="#item.Id" />
#item.Name (#item.Status)
<input type="file" name="files" />
<input name="submit" type="submit" value="upload final report" />
</form>
}
Question here was how can i take the data from input tag attribute to controller?
let say the #item.Id is 1234, how i get that in controller?
you can use
#Html.HiddenFor(m => m.yourPropertyname)
or using jquery ajax you can send the value to controller.
Maybe it's too late, but I would use asp-route-Id like:
<form id="submitfinal" method="post" asp-route-Id="#item.Id" asp-action="Upload" asp-controller="report" enctype="multipart/form-data">

Submit nested forms in Thymeleaf

I am developing a web application using spring boot, spring mvc and thymeleaf.
I have in template two nested forms with different action and two submit buttons as following:
<form name="form1" action="#" th:action="#{/action1}" method="post">
...
<form name="form2" action="#" th:action="#{/action2}" method="post">
...
<button type="submit" value="Import"/>
</form>
...
<button type="submit" value="Validate"/>
</form>
How to let button "Import" submit form2 not form1...??
Thank you.
You can not have nested forms because a form can not have another form as descendants. You can have many forms in a body not nested as you know. You can have one set for import and another set for remaining by sharing common backbean.
Please refer the link
4.10.3 The form element
Content model:
Flow content, but with no form element descendants.
<body> <form id="outer-form" class="form-horizontal form" th:action="#{/urlOuter}" th:object="${myBackBeanObject}" method="post">
<fieldset id="form-fieldset">
<button id="save" name="save" class="btn btn-primary">Outer Save</button>
</fieldset>
</form>
<form id="inner-form" class="form-horizontal form" th:action="#{/urlInner}" th:object="${myBackBeanObject}" method="post">
<fieldset id="form-fieldset">
<button id="save" name="save" class="btn btn-primary">inner Save</button>
</fieldset>
</form></body>

Can ASP.Net form have method=get or post attribute?

I am new to asp.net.
My question is, can a ASP.net form with runat="server", have a method attribute in it?
For example:
<form id="form1" runat="server" method="get">
.......
</form>
Is this possible?
Thanks for your answers.
I would like to share some points which I found.
By default the form with runat="server", will have method="post".
But when we request a page for the first time, (i.e) request is not a postback, the method="get".
And it becomes method="post",while postback.
I checked this by placing a piece of code in code behind:
In Page_Load():
if(Request.RequestType=="GET")
{
Response.Write("Request is a GET type");
}
else if(Request.RequestType=="POST")
{
Response.Write("Request is a POST type");
}
By default, the output
For the first request of that page: Request is a GET type
In postback: Request is a POST type
If i give the following code in the WebForm1.aspx
<form id="form1" runat="server" method="get">
For this, the output will be:
For the first request of that page: Request is a GET type
In postback: Request is a GET type
This is what I found.
Thank you very much for your responses.
yes you can try like below.
design part
you can design a form like :
<form id="form1" runat="server" method="post">
<input type="radio" name="Gender" value="male" id="test" checked="checked" />
male
<input type="radio" name="Gender" value="female" />female
<input type="submit" value="test" />
<asp:Button ID="btn" runat="server" Text="value" />
</form>
and how to get value from the form :
if (Request.Form["Gender"] != null)
{
string selectedGender = Request.Form["Gender"].ToString();
}
with this way you can get the value from form in asp.net.
i hope it will help you.
Yes,You can use use Method attribute..
The default will be Method="Post"
The form is always submitted to the page itself. If you specify an action attribute, it is ignored. If you omit the method attribute, it will be set to method="post" by default. Also, if you do not specify the name and id attributes, they are automatically assigned by ASP.NET.
If you select view source in an .aspx page containing a form containg these properties...
Please refer : http://www.w3schools.com/aspnet/aspnet_forms.asp

Form post data to ASHX hidden fields

I have next form and some ashx
<form action="FileUpload.ashx" method="POST" enctype="multipart/form-data" id="frmUpload">
<input id="fileupload" type="file" name="files[]" />
<input id="viewId" type="hidden" />
<input id="moduleId" type="hidden" />
<button id="btnUpload" type="submit">Upload</button>
</form>
I can get file inside of ProcessRequest(HttpContext context)
context.Request.Files - file containe file information, but context.Request.Form["viewId"] is empty.
That should I do to get hidden fields values ?
Thanks.
You need to add the name="viewid" also. The name attribute is used when you make post, not the id
read also: HTML input - name vs. id in the line "Used on form elements to submit information"

Dynamic HTTP POST instead of form action in asp.net

I have a simple asp.net page where a form action is done, which it takes to the 3d party url and that will return some data as a response. How can I achieve the job done without using static form action.
Below is the form action:
<form name="theForm" method="GET" action="page.aspx" >
<input type="hidden" name="asp" value="hidden values" />
<input type="hidden" name="url" value="http://www.google.com" />
<input type="submit" name="submit" />
</form>
Thanks in Advance.

Resources