Current Position:Home > How to call jsp in javascript

How to call jsp in javascript

Update:11-30Source: network consolidation
Advertisement
i am trying to show a confirm dialog and when the user click on the ok button, i want it to call a method inside my .java file. what i want to do is something like this:
<script>
var ans = confirm("Are u sure you want to over write file);
if(ans)
//call the method doUpload
else
//do nothing
</script>
/////////////.java///////////////
public class FileUploadBean{
public void doUpload(HttpServletRequest req, HttpServletResponse res){

The Best Answer

Advertisement
Something along these lines ought to do what you want:
<html>
<body>
<form name='foobar' action='foobar.jsp'>
<script language='Javascript'>
function askim() {
  if (confirm('Is you sure?')) {
    document.foobar.submit();
  } else return false;
</script>
<input type='button' value='Submit' onClick='askim()'>
</form>
</body>
</html>
Your mileage may vary.
But the idea here is that the Javascript merely submits the form if the user clicks "OK" on the confirmation pop-up. Otherwise, nothing happens. The form is submitted to a JSP file which accepts the request, does something (such as call your Java class), then prints out some HTML in response.
  • Set jsp from javascript Update:11-30

    I have three "div" tags in index.jsp , <div id='header'></div> <div id='body'></div> <div id='footer'></div> Now when window is loaded i want other jsp page to be set in the "body" div tag of index.j

  • Jsp in javascript Update:11-30

    hi can we use jsp in javascript for eg: <script> if(flag) <% respone.sendRedirect("--"); %> </script> or is there any other way of doing this type of things this is only an example. thx -jayYou can use JavaScript in a JSP. Java

  • JSP language javascript Update:11-30

    What is the problem? <%@ page language="javascript" %> <% var i; for ( i=1; i<5; i++ ) out.println("JSP whit JavaScript <br>"); %>What is the problem? <%@ page language="javascript" %> <% var i;

  • How to access variables across JSP and JavaScript? Update:10-11

    Hi, I have some .js files and in those files, some of the methods need to access to the variables that I'd declare in the jsp files. How do I do it? AnneYou can do it this way, but I'm not sure if this is what you had in mind. Say you had a java vari

  • How to pass values from JSTL to JSP or Javascript ? Update:10-11

    Hi All, Is it possible to share or use the variables which are declared are used by JSTL in JSP expression or scriplet code and in Java Script. Example: This Works: <fmt:set var="test" value="JSTL" /> <fmt:out value="${te

  • Problem in JSP with JavaScripts, which works perfectly in TOMCAT Update:10-11

    The peice of code below works without any problem in tomcat, which assign some values from a form named "frmOffice" which is in another jsp. In 9iAS it seems the values are not found. Also it says 'error on page'. What could be the reason. Pleas

  • WL vs. WL-express and JSP vs. javascript/SQL Update:10-11

    folks- i am trying to convince a certain party to disband a web-based job tracking system being written in ASP, javascript, html, css and SQL. it will be hosted on MS webserver running NT. i am trying to convince them to use JSP and WL express. i hav

  • Jsp and javascript problem Update:10-11

    I have a JSP page with a table of n rows. Each row has the option of having           a dropdown list appear on that particular row. The user should have the           ability to make a selection from the drop down list and have the page change      

  • Using JSTL variables in JSP or Javascript. Possible ? Update:10-11

    Hi All, Is it possible to share or use the variables which are declared are used by JSTL in JSP expression or scriplet code and in Java Script. Example: This Works: <fmt:set var="test" value="JSTL" /> <fmt:out value="${te

  • How to do  validation in jsp using javascript Update:11-30

    how to do validation in jsp using javascriptThe same way you do with any HTML page. Catch the onclick/onsubmit event, do your validation in javascript and then allow/cancel the action as required. However this is javascript validation only - javascri