File Upload in Servlets - ajax

Hi I have a form having upload file and an input type="text".
<input type="file" id="uploadFile" name="file" required="required">
<input type="text" id="purpose" name="purpose" required="required">
Now when the user clicks the button I want to hit a servlet through AJAX and set the file to a required folder and also retrieve the purpose input value and put it in my table.
Any help how can I achieve this ?

I encountered with this problem yesterday. As developerwjk said, I used:
commons-fileupload.jar
commons-io.jar
For more information see this useful question.

Related

How do I emulate a button press in web scraping?

Hello I am using colly to scrape my university's classes. The web page is simple enough
<form id="rngID" method="post" action="../../../SOME_REALLY_LONG_PATH">
<input type="hidden" name="rngID_hf_0" id="rngID_hf_0">
<label for="user">User:</label>
<input type="text" maxlength="20" value="" name="user" class="required valid">
<label for="password">Password:</label>
<input type="password" maxlength="20" value="" name="password" class="required valid">
<input type="hidden" id="js" value="1" name="js" class="valid">
<script>
/*<![CDATA[*/
document.getElementById("js").value = "1"
/*]]>*/
</script>
<input type="submit" class="btn-blue valid" name="login" id="rngID+2" value="Ingresar">
</form>
I find myself needing to interact with the website's contents. I understand I have the underlying objects associated to the HTML file recieved, but I am struggling to find how to trigger the submit action. Moreover I am unsure how to set the html input values with colly (username and password).
Can this not be done in colly? It seems to have good cookie management which fits in what I'm looking fo
Colly doesn't resolve/render the HTML DOM to the same degree as a web browser in a few ways, but the most notable is that it doesn't interpret and run JavaScript. So there is no direct way to emulate button presses with it.
However, forms can be submitted through post requests and goColly supports this with the Post method for a collector.

Form input old value in laravel 5.6

I have a search form input where i want to display the searchterm value in the searchbox after searching on the results page.
I tried the following which is not working
<input type="text" name="search" value="{{ old('search') }}" placeholder="Search help articles" class="form-control form-control-gray col-md-10">
What is incorrect in the value=""
old() is used when flashing data to the session. This is mostly used for forms which involve redirects back when something fails. Read about old input here.
request() should be used here since you're wanting to display the value that was submitted on that request.

Custom comments template in BlogEngine

When someone wants to write a comment, It has to set Name, Email, Web Site and finally comments . How should I modify this template to use just the Comment? Because It has these info when admin registered him. I dont want to store false info.
Thanks for your help.
Since you didn't specify the version I am assuming you are running on the current latest (3.1).
The comment submission form is controlled by the CommentForm.cshtml in the siteroot/Custom/Theme/YourCurrentTheme folder. Here is a portion of the form from the Garland-Revisited theme.
<p>
<label for="txtName" class="lbl-user">#Resources.labels.name *</label>
<input type="text" class="txt-user" name="txtName" id="txtName" />
</p>
<p>
<label for="txtEmail" class="lbl-email">#Resources.labels.email *</label>
<input type="text" class="txt-email" id="txtEmail" />
</p>
<p id="commentCompose">
<textarea class="txt-content" id="txtContent" cols="50" rows="10" name="txtContent"></textarea>
</p>
The simplest path is probably to avoid changing the submission handler and convert the input type to hidden and prefill the value with their logged in credentials. A possible sample.
<input type="hidden" id="txtName" value="#SomeC#CodeToReadTheValuesFromTheLoggedInInformation" />
<input type="hidden" id="txtEmail" value="#SomeC#CodeToReadTheValuesFromTheLoggedInInformation" />
<p id="commentCompose">
<textarea class="txt-content" id="txtContent" cols="50" rows="10" name="txtContent"></textarea>
</p>
This does have security implications. You are trusting your users not to mess with the hidden values in the form. On an open website this probably isn't safe enough and you will have to look at changing the submit handler.
Changing the submit handler does have its own maintenance issues since you will be running a custom version of the software that won't upgrade cleanly when the next version comes out. It's up to you to decide what is the better path in your situation.

Hidden inputs are missing from Request in Asp.net mvc3

I'm using asp.net mvc3 ajax.beginform, and recently I've encountered a very strange problem.
It seems that some of the hidden input's I've placed inside the form do not exist in the request object.
I am not changing these values in any way after the post.
Any idea what is the reason?
Here's an example of a form that's giving me some trouble.
<form action="/PriceListItems/PriceUpdate" data-ajax="true" data-ajax-method="Post" id="form0" method="post">
<input id="item_Id" name="item.Id" type="hidden" value="3">
<input id="price_TariffId" name="price.TariffId" type="hidden" value="1">
<input class="input-mini"
data-val="true"
data-val-number="The field Price must be a number."
data-val-regex="incorrect number"
data-val-regex-pattern="(^N/A$)|(^[-]?(\d+)(\.\d{0,3})?$)|(^[-]?(\d{1,3},(\d{3},)*\d{3}(\.\d{1,3})?|\d{1,3}(\.\d{1,3})?)$)"
data-val-required="שדה זה הינו חובה"
id="itemTariff_3_1"
name="price.Price"
onchange="postThis(this);"
type="text"
value="300.00">
<span class="help-block">
<span class="field-validation-valid"
data-valmsg-for="itemTariff_3_1"
data-valmsg-replace="true"></span>
</span>
</form>
Thanks!
solved it, but it was quite a disappointing solution..:
i've replaced every jquery related script in my site so that it'll arrive from a CDN rather from my local files, but in the original versions.
and that was it.
everything suddenly started to click together.
frustrating, but works.
thanks,
Nir

Submit button to submit a form in dreamweaver cs4

I can not get the form to submit with the button. The best luck I have had is to send a generic email with no data attached.
This is the code:
<input name="mailto: info#thebellimagegroup.com" type="submit" onClick=mailto: info#thebellimagegroup.com value="Submit Form" id="mailto: info#thebellimagegroup.com" >
the value is: /frms/contact.con
Can anyone help????
Submit buttons generally aren't used for storing information -- as a rule, they just submit the page, and any other information (such as the email recipient's address) will be put in other inputs in the form. For example:
<form action="/frms/contact.con" method="post">
<label>Subject: <input type="text" name="subject" value="" /></label>
<label for="message-editor">Message</label>
<textarea name="message" rows="6" cols="60" id="message-editor"></textarea>
<input type="submit" value="Submit" />
<input type="hidden" name="recipient" value="info#thebellimagegroup.com" />
</form>
In this example, the "action" attribute of the FORM element specifies the script on the server which will process the information once someone clicks Submit. The hidden input which I have named "recipient" specifies the email address, and the value of that will be sent in along with the rest of the form when it's submitted. All the submit button itself does is cause the browser to send the finished form off to the server for processing.
Note that the example I've given here probably won't work with your particular script, because the names I've selected for the example inputs ("subject", "message", and "recipient") probably don't match the ones your script expects.
Do you have documentation on how the /frms/contact.con script works? If so, check it -- it should tell you what to name your form elements. Failing that, and assuming that you know whatever programming language it was written in, you could read the code in contact.con to see what names it's expecting.
If all else fails, try a different server-side script, there are about eight zillion available.

Resources