How to load again html table in jsp page - html

Here in my registration page i did servlet page in insert values to Data Base and i need to display all the insert values from Data Base in html table using in jsp when i enter all the details click add button it shows message in another page when i go back to the previous page table not update with latest values when i reload page it shows values how can i do this
my image after clicking add button table not updated: image description here

Call page reload with javascript, on button press. You can do this in two ways:
1)
<input type="submit" value="submit" onsubmit="window.location.reload()"/>
in case it doesn't work, check the first answer on How can I refresh a form page after the form submits to _blank?
2)
<input type="submit" value="submit" onclick="refresh()" />
add the following javascript code just below:
<script type="text/javascript">
function refresh (){
window.location.reload();
}
</script>
The above two solutions are equivalent. A different approach is to set the meta attribute of the html page, specifying the refresh interval. Please take a look at https://www.codeproject.com/Questions/250016/refresh-the-jsp-page
That gives a third solution:
3)
<%
if(session.getAttribute("refreshCount") != null &&
session.getAttribute("refreshCount") == true )
{
response.setHeader("REFRESH", "0"); //refresh page once per submit
session.setAttribute("refreshCount", false);
}
%>
In the servlet, when you save data to database, also call
HttpSession session=request.getSession();
session.setAttribute("refreshCount",true);
4)
In the servlet, use redirect instead of forward (you will be redirecting to the same page)
how to reload JSP page after submit form data
http://www.javapractices.com/topic/TopicAction.do?Id=181

Related

How to get clicked img src and pass it to the next view function

I am using flask to deploy my model for image similarity search. To run it, I will have two pages:
1) first page (say, query.html) that shows a randomly generated image from my dataset; users can continue to refresh this page till they see an item that they like. In html, it would be something like <img src="{{ random_path }}" alt="">. When the user is satisfied, the image needs to be clicked to direct to the next page;
2) second page (say, results.html) that takes the img src from the first page, and run the model at backend and return the similar images.
I am now confused how I should link step 1) to step 2) - how to get the img src on click and pass that information on to the next step?
You can use a form with hidden input tags and make a post request (More on flask's post request here) to pass on the data from one page to the other. In code it would look something like this:
HTML:
<html>
<body>
<form action = "/imagematch" method = "post">
<p><input type = "hidden" name = "imagesrc" /></p>
<p><input type = "submit" value = "submit" /></p>
</form>
</body>
</html>
Python Backend:
#app.route('/imagematch',methods = ['GET', 'POST'])
def login():
if request.method == 'POST':
user = request.form.get('imagesrc')
Alternatively you can use JavaScript localstorage/sessionStorage. More on localstorage here:
Write a <form> and place the <input type="hidden"> (with base64 format of the image as value) or <input type="hidden"> (with the server file path as value) whichever comfortable and upon submitting the form the image path/base64 format of the image as value will be sent to server.
Or
Using Javascript or JQuery upon user selects the image, send the image to the server via a AJAX request and do whatever you want at the server-side and return the status to the user accordingly.
Option 1 is simple and straight forward and you need to deal with base64 conversion.
Option 2 is a little complex and needs good JQuery expertise.

How to show success message on form submit - ASP.NET MVC 5

I created a normal contact form using tag in my view.
My submit button consists of
<input name="skip_Submit" type="submit" value="Submit" />
When the form is submitted successfully it should show a message notification of Successful.
I tried using TempData["message"] = "Successful"; in controller and using it with if command in view but doesn't work.
in your controller, you can do this:
ViewData["Message"] = "Success"
and in your view you you can check if there is a message to display, and if so than display it:
#if (ViewData["Message"] != null)
<div>success</div>
or
TempData can be used like a dictionary. Each saved value lasts for the current and the next request. Perfect for redirects.
this.TempData["messages"] = "Success!";
return RedirectToAction("YourAction");
If you are using post method to do your updates, then return the same view after update with value in TempData or ViewBag. If you are doing update using ajax method, then make success div visible using jquery after calling update method(it doesn't needs redirection)

Html data attribute in Coldfusion form submission

I understand how to pull out the data attribute in JQuery from an HTML form, but can it be done from within a .cfc controller to which a form is passed?
Page.cfm
<cfform action="controller.cfc" method="getData">
<cfinput name="uploadMyData" type="submit" data-primaryID="123">
</cfform>
Controller.cfc
function getData(rc){
writeDump(rc.uploadMyData.?????(primaryId)????);
}
Not sure if the data attribute is stored in any way in the struct.
I tried a getMetaData on the rc.uploadMyData but just got a list of java functions.
Update
Adrian J. Moreno
Data attributes are just markup that impact the internal data object of the element. They are not part of a form request. You wouldn't submit a form to a CFC file either. Using Ajax, you can read the value from the data attribute and pass it to the server as part of the request's data packet.
So in Page.cfm
<script type="text/javascript">
var otherData = $("#myForm").serialize();
function sendForm(){
var primaryID = $("#submitData").data("primaryID");
jQuery.post("urlpath/controller/",'{"id":'+''+primaryID+'}', function(dataReturn, status){
//I want to get my form and submit the other data as well to the controller
}
}
</script>
<form id="myForm" action="sendForm()">
<input name="uploadMyData" id="submitData" type="submit" data-primaryID="123">
<input name="importantThing" value="#importantVariable#" type="text">
</form>
pass it to the server as part of the request's data packet.
how would I pass them together?
I want this form submission to redirect to another page so I don't see how I couldn't use the controller? The form data should go the newPage.cfc to process it and get it ready for output on newPage.cfm. I'm using framework one but that doesn't change much.
Thanks for the help, what do you think?
Update 2
Ok, now I ask myself why I would want to submit a form with both ajax and coldfusion form submission together? I realize that's not what should be done. I can either
Submit the form via JQuery/Ajax with no page reload, and include the data attribute in the post url and include the serialized form data
Page.cfm
<script type="text/javascript">
var otherData = $("#myForm").serialize();
function sendForm(){
var primaryID = $("#submitData").data("primaryID");
jQuery.post("controller/method/?primaryId="+primaryID+"",otherData, function(dataReturn, status){
//do stuff with dataReturn or do a javascript redirect
}
}
</script>
Controller.cfc
function method(requestContext){
//do stuff with that otherData, all stored in request context. includes the primaryID value i appended to the url
//send it back to the Page.cfm
fw.renderData("rawjson",jsonString,200,"");
}
and if that made it back ok, I could run a function back in my original view with that information. Like display it on the page.
Submit the form traditionally which would result in a page reload. Include a hidden input type with the value that I want to pass.
Page.cfm
<cfform action="controller.method" method="getData">
<cfinput name="uploadMyData" type="submit" value="Submit Form Button">
<cfinput name="primaryID" type="hidden" value="123">
</cfform>
Controller.cfc
function method(requestContext){
//do stuff with requestContext.primaryID
//go to the view method.cfm or do a fw.redirect("new page or back to the page i came from");
}
Why would we want to submit the form twice? just do one or the other.
Matt, I think you're confused about a number of things that are quite basic to HTML, JavaScript and jQuery and have nothing to do with ColdFusion.
Let's start with an HTML Form.
<form id="{{unique_dom_value}}" action="{{uri}}" method="{{http_verb}}">
unique_dom_value: Some string unique to the document. Allows you to reference the entire form object using JavaScript.
uri: The URI to which you submit the form for processing.
http_verb: Defaults to GET, but you should most often use POST.
The URI you're trying to post to in just controller.cfc, but that won't do anything but redirect you to the ColdFusion CFC inspector.
In the context of most MVC frameworks, index.cfm?event=handler.action uses the underlying framework to call a function named action within a CFC named handler. Without a framework, you have to do that manually. So if you have a CFC named controller.cfc and want to send your form data to a function named myFunction, you need to say action="controller.cfc?method=myFunction.
But that's not right either. When you submit a form, the browser expects to load the URI that's found in the action attribute. But your CFC function doesn't respond with HTML, it responds with something else. Maybe a query object, maybe JSON. This is why you would use jQuery.Ajax() to send the form data (including the data attribute values) to the CFC's function, which should return data in JSON. Once you get a response, you can continue processing on the same page or redirect to another page.
However, since you're using Framework One, I would look into the documentation on using renderData() within one of your handler functions.

submit a form but dont go to the submit. Instead stay on the current page

I have an submit form and when i submit it goes to the url of the submit form(in this situation its taak/add_taak) is there a possibility to stay on the page where the submit is done from. underneath you see the html form for the post. is there an html function to stay on the current page where you have the submit form?
<form target="_top" name="form" action="../../../taak/add_taak" method="POST">
Are you wanting to retrieve data from the posted page ?
You could use javascript / jquery to do a ajax call to the page
$.post('/taak/addtaak?value1=' + txtValue + '&value2=' + txtValue2, function (data) {
//this is if you want to post data
});
$.get('/taak/addtaak?value1=' + txtValue + '&value2=' + txtValue2, function (data) {
//this is if you want to retrieve data
});
This would allow you to post to the page without leaving your current page
please note, you will need to include the jquery library in your website
You could also look here
Submitting HTML form using Jquery AJAX
Edit *
Added link to related Stack Overflow Question

TokenInput - getting values from multiple search fields

I'm using Loopj's TokenInput and it's working fine.
I have three search boxes on the same page - one each for three different search attributes and each with its own external data source (in this case, search by ship name, ship class and ship type). Of course, there are three 'Submit' buttons, one for each search box.
My Problem: Clicking any 'Submit' button only returns values for its own search box (based on included script-refer below). What I'd like is to click ANY button and get the values for ALL the search boxes so that I can create a MySQL query.
<script type="text/javascript">
$(document).ready(function() {
$("input[type=button]").click(function () {
alert("Would submit: " + $(this).siblings("input[type=text]").val());
});
});
</script>
Note: This earlier question "Using tokeninput jquery plugin on more than one input on a page".seems related but the answers to that question didn't address this issue.
After some further testing, I've figured out the answer and I'll include it here for the sake of completeness. Unfortunately this highlights just how little I know about coding...
The javascript 'alert' script is a red-herring. It doesn't magically get the token values out of thin air. The token values are already stored in the relevant input fields.
The "Submit" buttons are a red-herring. That's because they are
". They're just there to trigger the
javascript alert, they can't submit a form.
You need a form! The "TokenInput" demos show how the plugin works, but they're meant to be used IN A FORM.
I added a form field at the top of my page and a closing form field (</form>) at the bottom of the page. The result was that my three search boxes were inside the form. Note the action is to retrieve the same page and method = post.
`<form id="myshiptype" name="pixsearchform" action="<?php echo $_SERVER[REQUEST_URI]; ?>" method="post" >`
I changed the sample input "name" fields from 'blah' to something more meaningful - shipid, classid and typeid.
I added a Submit button (of the <input type="Submit" /> variety) to the bottom of the form. <input type="submit" id="update" name="update" value="Update search" />
I added some debugging code to the page to show the values of the input fields after the Submit button is clicked.
<?php
$postvalues = "";
if ($_POST) {
$kv = array();
foreach ($_POST as $key => $value) {
$kv[] = "$key=$value";
}
$postvalues = join("&", $kv);
}
echo "post values are ".$postvalues;
?>
Here's a sample of the debug - "post values are shipid=34&classid=&typeid=677,638&update=Update search"
Next steps are to adapt the form to Ajax and also disable the "Enter" key in the form (for when a user hits Enter in an empty Search).