JSP & JavaScript

Discussions

Web tier: servlets, JSP, Web frameworks: JSP & JavaScript

  1. JSP & JavaScript (2 messages)

    Hello everyone,
    I have this problem, I have a web application based on JSPs and servlets. I have to fill several form fields and control every field not to be blank before sending it to the servlet. As a project specification I cannot use a servlet or a bean to do this control, so I thought to do it using JavaScript, but I cannot figure out how to code it! Can anyone help me please sending me or here any suggestion or/and links to samples of JSP mixed with JavaScript ?
    Thanks,Fabio
    (f dot fornaro at inwind dot it)

    Threaded Messages (2)

  2. JSP & JavaScript[ Go to top ]

    Hope this will help...


    <%@ page import="whatever.*.*,
             errorPage="error.jsp"
    %>

    <html>
    <head>
    <title>Title here</title>
    <jsp:useBean >

       <%
    //java code starts
          String strJsp ="Hi I am jsp variable";
          int i =10;
          
          if (session != null) {
          .......
          } else {
             response.sendRedirect(response.encodeRedirectURL("error.jsp?eror=Invalid+Session"));
             username = "";
          }
    //java code starts--ends
       %>
    </jsp:useBean>

    <script LANGUAGE="JAVASCRIPT">
    //java script variables
    var count = 0;
    //following line uses jsp var in javascript
    var fromjsp = "<%= strJsp %>";
    var uni = Math.random();

    function intialize() {
       alert("Value from JSP is" +fromjsp);
    }

    function sayhi(){
       alert("hi");
    }
    </script>
    </head>

    <body bgcolor="#DADADA" ONLOAD="javascript:intialize();" >

    <form method="post" name="from1" action="" >
    <input type="text" value="<%= strJsp %>" >
    <input type="button" name="click me" onClick="sayhi()">
    </form>
    </body>
    </html>
  3. JSP & JavaScript[ Go to top ]

    Yeah, that was a really good begin.
    Thanks,
    Fabio