Again combining javascript and jsp

can i do the post methode of a form inner a javascript function?
i want first check whether the reqiered fileds r filled and the do the post action.
Andre

Yeah that is really quite simple....
function FormValidation()
//do Validation stuff here
document.MyForm.submit;
<HTML><BODY>
<input type=submit name=submit value="Submit
onclick = "FormValidation(); return false;">
The return false will cancel the submit action.
null

Similar Messages

  • Parameters b/w javascript and JSp

    how i can pass values between javascript and jsp .
    ( java script varaible in the JSP part & jsp object in the javascript code )

    Since Java script is on the client side , to get the value of a java script variable into jsp, u have to set some form field variable and submit it to the server again. So, it can be something like:
    <script>
    function submit()
         var scriptVar = 12;
         document.form1.formVariable.value=scriptVar;
         document.form1.submit();
    </script>
    <%
    System.out.println("Script variable value = " +request.getParameter("formVariable"));
    %>
    <form name="form1" method="post">
    <input type="hidden" name="formVariable" value=""/>
    <input type="button" name="bSubmit" value="Submit" onclick="javascript:submit()" />
    </form>
    The first time this jsp is called, the value of formVariable will be null.
    The next time, when u click on submit button, the value will be 12.
    I have not tested this. There might be some syntax errors. Just try it out. Also, make sure that u don't end up submitting the form in an infinite loop by using the submit() generally in the script. Hope this helps.

  • How to combine servlet and jsp

    I'm doing a project. My friend using jsp. and i using servlet..
    we are confused, how to combine servlet and jsp. or we can just use redirect??
    but it's still doesn't work properly...thanks for your helpp

    You can use RequestDispatcher interface for calling a JSP from a Servlet, or vice-versa.
    Following is the code for sending output to a JSP page from a servlet:
    javax.servlet.RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(�/Ashu.jsp�);
    request.setAttribute(�Name�,�Ashutosh�);
    dispatcher.forward(request,response);
    - Ashutosh

  • Mix JavaScript and JSP

    Hi.
    I have jsp and javascript mixed when I click a check call a function javascript for example:
    //JavaScript
    function Hola(numerop) {
              idRol = Number(numerop)
              <%nombreRol = roles.get(numerop)%> }
    //Form
    <input type="checkbox" name="<%=roles.get(sum)%>" value="<%=roles.get(sum)%>" onClick="Hola('<%=roles.get(sum)%>')">
    In the function numerop is a number but in the jsp code numerop is undefined.
    How I can mixed javaScript and jsp??
    Please I need help you.

    Remember that the JSP runs on the server and generates the HTML, including Javascript. The Javascript runs on the browser after the JSP is finished. So you cannot do whatever it is you expected that to do.

  • How to combine JavaScript within JSP statements

    I have trouble figuring out how you can get a value from your JavaScript and insert it into a JSP Object.
    I have a JavaScript function like this:
    function setCookie(user) {
    <%
    Cookie cookie[] = request.getCookies();
    for (int q = 0; i < cookie.length; i++)
         if (cookie[q].getName().equals("username")) {
         cookie[q].setValue(user);
         break;
    %>
    I wish to add the user variable of the JavaScript into the cookie[q]'s value. Is this possible? If so could anyone please help me in telling how to do this or maybe an alternative method.
    Thank You

    A call to JavaScript goes to the browser on client. A JSP request goes to the JSP container on the server. Therefore to
    get a value from your JavaScript and insert it into a JSP Object.will require a request to the server and response back. You could use a form to send the "user" value to the server and the JSP could send response to the browser to set the cookie.
    or maybe an alternative methodWhy don't you use a pure JavaScript solution. Your JavaScript function could set the cookie directly. JavaScript can manipulate cookies by using the "cookie" property of the Document object.

  • Problem in JavaScript and JSP

    Hello all, I have a problem. I am using a file upload box in my JSP page.
    And I want to put some validations on the input of that file - see if it exists, check its size, or may be its type. I tried to use ActiveXObject in the JavaScript but it gives an error - ActiveXObject is not defined. Is not allowed to use ActiveX object in JavaScript. if not then where can we use such an object. I used such a FileSystemObject in VbScript, but that too was a independent running scripts like .vbs file. Can anybody help?

    Use of ActiveX object is strongly discouraged, however
    Check if this solution solves your problem
    Inorder to use ActiveX Objects ,check whether ActiveX object s are enabled in IE.
    Goto IE>Internet Options>Security Tab>click button Custom level>
         scroll to 'Run ActiveX controls and plug-ins'>select �enable�.
         also enable "Initialize and script ActiveX control not marked as safe."

  • Javascript and jsp forms

    Hi,
    I have the following java code what I am trying to do is to use some java script to read values from the buttons. As per my thinking the javascript code when called should print out the no of radio buttons but what it is giving is undefined. Could somebody point out what I ma doing wrong???????
    Its already drawing me crazy.
    <dsp:form name="students" action="../../check.jsp" method="post">
                <P>books  </P>
          <INPUT type="radio" name="books" value="Java2InANutShell">
                                   Java 2 in a nutshell
                          </INPUT>
                          <br><br>
         <input type="button" value="Length" id="length"      name="Log In"  onclick="launchAutoWindow()"/>
    </dsp:form>
    function launchAutoWindow(id)
    alert(document.students.books.length);
    }

    You only have one radio with the name of "books" on
    the page.
    If you have only one, "document.students.books"
    evaluates directly to the radio object
    If there is more than one object with that name, it
    evaluates to an array of the objects. At that point,
    length would be defined.
    So if length is not defined, you know you only have
    one :-)
    Don't you just love javascript?Thanx mate. That solved the problem. I would have never figured it out myself. Thats kindaa silly but as long as it works ;)
    Thanx again.

  • Can I combine ASP and JSP pages?

    Hi all,
    Maybe a dumb question...
    but Can I have ASP pages in my JSP application?
    My problem is as follows:
    In the JSP pages of my application, I have some links to ASP application:
    http://domain/app.asp
    Now IIS is running on another port. But I do not want to go through all my JSP and change the above link to:
    http://domain:port/app.asp
    Instead any request to http://domain/app.asp should be automatically forwarded to http://domain:port/app.asp
    How can this be done? I am using Tomcat as my JSP container.
    m_asu

    Actually that is not what I am looking for. I dont want to 'buy' any product. I dont want to deploy ASP application with the JSP application. I just want to redirect the client to another website through an ASP page.
    Only catch is that this ASP page needs to sit in my JSP container (Apache Tomcat). Is this possible?
    m_asu

  • Relating javascript and jsp

    hi
    i have one jsp file;in that i have written
    <%
    response.setContentType("application/ms-word");
    %>
    <script language="JavaScript">
    document.write("ss")
    </script>
    i am able to see ms-word document but i couldnt see output ss on the word document;will jsp doesnt access javascript after calling response.setContentType(("application/ms-word")?;if i want to see ss on the word document thru javascript wat i have to do;
    plzz help
    chaitu

    See http://forum.java.sun.com/thread.jsp?forum=45&thread=390559&tstart=0&trange=30

  • How to combine javascript, flex

    Hi,
    This is Siva Kumar. I am begginer to adobe flex. I have lot
    of doubts regardng flex. Actually I have different requirements for
    that I think I have to combine javascript and jsp with Flex. Is it
    possible to combine/integrate javascript code with flex. If
    possible anybody help me to in this issue.
    Thanks & Regards,
    Siva Kumar

    A call to JavaScript goes to the browser on client. A JSP request goes to the JSP container on the server. Therefore to
    get a value from your JavaScript and insert it into a JSP Object.will require a request to the server and response back. You could use a form to send the "user" value to the server and the JSP could send response to the browser to set the cookie.
    or maybe an alternative methodWhy don't you use a pure JavaScript solution. Your JavaScript function could set the cookie directly. JavaScript can manipulate cookies by using the "cookie" property of the Document object.

  • Connecting databeses with WML and JSP pages..!

    I need information about how to connect databases with wap technologies using wml and jsp , I am waiting your resources, codes and helps.. And I would like to remind you , I am beginner about this topic , Only things that I know are Jsp and WML , I have no experience about wap and how to combine wml and jsp , So please be helper while you send your messages , If all your messages contains much detailed and supported complete sources and files , it will more helpfull for me ..
    Thanks in Advance.
    P.S : 1- ) if you want to contact direclty , mail address : [email protected]
    2-) Don't post me complex references' URL , I have already made search on google,yahoo and etc

    Additionally , I would like to learn what I have to need for this project .. Now , I already have winwap wap emulator and Websphere Studio.. Do I need special wap server or something else to test my applications..
    Please , hurry up .. I really need your helps..
    Ergin

  • Embed javascript in JSP

    hi
    i want to store the query string of an URL in a flat file. but i want to append the name of the person who's passing the query string by prompting him to enter his/her name. i have a code something like this
    FileWriter outputFile = new FileWriter("Libset1.txt", true);
    BufferedWriter outputBuffer= new BufferedWriter(outputFile);
    final PrintWriter outputWriter = new PrintWriter(outputBuffer);
    //writes all data to the output file
    for (int i=0; i<Selected_set1.length; i++)
    outputWriter.println("some javascript to prompt the user goes here..." + Selected_set1);
    outputWriter.close(); //closes output file
    i want to embed some javascript in place "some javascript to prompt the user goes here..." prompting the user to enter his name..
    is it possible to do that. if yes, how.?
    sorry i'm just a beginner, it might look silly for you...please help...
    thanks in advance..

    First of all, you need to understand how Javascript and JSP work together....they don't. Javascript is a client side scripting language, which means that it executes and runs in the client browser after the page has been loaded. JSP is purely server side, it only runs while the request is being serviced, or while it's generating the HTML to send back to the client browser.
    To do what you're asking for should be pretty easy using javascript. You should be able to use the Javascript onClick() event for the link the user is clicking on to execute a Javascript method that prompts the user for their name.
    You might try something like this...
    <script language="JavaScript">
    function promptUser(newPage)
      var username = prompt("Please enter your username");
      if(username)
        document.location = newPage + "&username=" + username;
    }</script>
    Click Here Please!
    This will result in a query string that looks something like mypage.jsp?id=23&view=whatever&username=john
    Make sense?

  • WL vs. WL-express and JSP vs. javascript/SQL

    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 have done two years of EJB
    component work on weblogic, however, i have not
    done work with JSP or thin-clients. i was mostly
    business-logic.
    anyway i have some questions and need some
    direction. i already know JSP is better than
    ASP/javascript etc. because:
    * ASP is proprietary. ditto for VBscript
    * with an IDE creating JSP is easy and JSP
    automatically creates servlets which is way
    faster than by hand
    * JSP is JAVA based and hence benefits from
    all the portability pluses of JAVA
    but here are the more difficult questions:
    * why is WL express better than an MS
    web server? (not including WL market share
    and size. after all MS can claim that)
    * since WL express does not have an EJB
    container, how do you access the database?
    via JDBC? does one just have JDBC code
    floating around?
    * since there is no EJB container how does
    one separate presentation from logic from
    data access? this is a major downside of
    javascript, html, css and SQL etc.
    * if a web app grows beyond JSP with WL express
    into the need for an EJB container, i would
    think that most of the app needs to re-written
    as business-logic must be refactored into EJBs
    and all JDBC code will be replaced by container
    managed beans. this sounds a like a lot of
    rework.
    * isn't JSP slower than javascript as the
    servlet and hmtl code is bounced back and
    force across the network?
    with respect to architecture, scalability,
    and robustness what are the downsides to an
    MS webserver and non-JSP coding?

    * since WL express does not have an EJB
    container, how do you access the database?
    via JDBC? does one just have JDBC code
    floating around?
    Use JDO or an OR-mapper or embed JDBC into your own data access classes.
    * since there is no EJB container how does
    one separate presentation from logic from
    data access? this is a major downside of
    javascript, html, css and SQL etc.
    Presentation=JSP
    Logic=Servlet
    Data access=JDO or similar
    * if a web app grows beyond JSP with WL express
    into the need for an EJB container, i would
    think that most of the app needs to re-written
    as business-logic must be refactored into EJBs
    and all JDBC code will be replaced by container
    managed beans. this sounds a like a lot of
    rework.
    You should be able to tell up front if it a tx-intensive app that requires
    WLS.
    * isn't JSP slower than javascript as the
    servlet and hmtl code is bounced back and
    force across the network?
    They aren't exclusive. For dynamic pages, use Javascript on the front end,
    JSP on the back.
    * with respect to architecture, scalability,
    and robustness what are the downsides to an
    MS webserver and non-JSP coding?
    In the real world, and for most apps, while Java has the architectural edge,
    they both have similar scalability and similar robustness. MS gives you no
    choice though, and you rewrite every time they see a new buzzword. You can't
    leave MS-land without abandoning almost everything. You can leave WLS in a
    week if you have to.
    It's an investment. Invest wisely.
    Peace,
    Cameron Purdy
    Tangosol, Inc.
    Clustering Weblogic? You're either using Coherence, or you should be!
    Download a Tangosol Coherence eval today at http://www.tangosol.com/
    "shane miller" <[email protected]> wrote in message
    news:[email protected]...
    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 have done two years of EJB
    component work on weblogic, however, i have not
    done work with JSP or thin-clients. i was mostly
    business-logic.
    anyway i have some questions and need some
    direction. i already know JSP is better than
    ASP/javascript etc. because:
    * ASP is proprietary. ditto for VBscript
    * with an IDE creating JSP is easy and JSP
    automatically creates servlets which is way
    faster than by hand
    * JSP is JAVA based and hence benefits from
    all the portability pluses of JAVA
    but here are the more difficult questions:
    * why is WL express better than an MS
    web server? (not including WL market share
    and size. after all MS can claim that)
    * since WL express does not have an EJB
    container, how do you access the database?
    via JDBC? does one just have JDBC code
    floating around?
    * since there is no EJB container how does
    one separate presentation from logic from
    data access? this is a major downside of
    javascript, html, css and SQL etc.
    * if a web app grows beyond JSP with WL express
    into the need for an EJB container, i would
    think that most of the app needs to re-written
    as business-logic must be refactored into EJBs
    and all JDBC code will be replaced by container
    managed beans. this sounds a like a lot of
    rework.
    * isn't JSP slower than javascript as the
    servlet and hmtl code is bounced back and
    force across the network?
    with respect to architecture, scalability,
    and robustness what are the downsides to an
    MS webserver and non-JSP coding?

  • Servlet and JSP combination and design issue

    My task is to generate the list box dynamically based on the input XML file.
    I create a JSP page and a servlet.
    http://www.myserver.com/page1.jsp
    In page1.jsp, I have the following to call servlet from JSP page
    <jsp:include page="myproj.TableGeneration"/>
    In my case, I think I don't need servlet at all, but just Java Bean
    class to generate the table. And JSP page call that Java Bean class.
    But in what situation we need the combination of servlet and JSP?
    What do you think? Any ideas? Thanks!

    Trying to keep the data separate from the view is always a good idea
    I have used XML in a similar way - the XML is the data, this is read and it is uses to populate various page beans - the beans are then simply used in the JSP page to get the information only

  • FORM and JSP in the same page

    Hello All
    Is it possible to pass variable from a html textbox to a JSP? but they both are in the same page.
    For this purpose, I have a created a index.html, which contain two frames, top.html and bottom.jsp. There is a textbox in the top.html, it collects 2 variables and use form action "POST" to call bottom.jsp to display a graph.
    However after I run this page on Tomcat, it gave me error message in the bottom.html:
    The server encountered an internal error () that prevented it from fulfilling this request.
    Can anyone teach me how to solve this problem? Thanks a lot
    Viola
    index.html
    ===============================
    (FRAME) top.html
    <form action="bottom.jsp" method="post">
    <input type="text" name="apple">
    <input type="text" name="orange">
    ===============================
    (FRAME) bottom.jsp
    String apple = request.getParameter("apple");
    String orange = request.getParameter("orange");
    use those two variables to do something
    and display a graph

    The problem is that both pages are loaded @ the same time so when the getParameter gets executed the parameters are null and this is the probable cause of your error. Another problem is the action in form will cause the bottom to go into tops frame and not have anything to do with the other frame. If you want data to go from one frame to another while the user still sees them look @ DHTML, JavaScript and IFrames.
    HTH,
    J.Clancey

Maybe you are looking for