1

I have this cezar.jsp file and the following code inside my head below. I have a textarea and I want to pass the value as a parameter for a java function.

<head>
    <%@ page import="cpd.CezarBun" %>
    <script>
    <%
        cpd.CezarBun cezar = new cpd.CezarBun();

        //don`t know how to use scripplets here
        String contentIn = document.getElementById('myTextArea').value; 
        cezar.criptare(contentIn); //takes a String parameter

    %>
    </scrupt>
</head>
eddie
  • 1,252
  • 3
  • 15
  • 20
que1326
  • 2,227
  • 4
  • 41
  • 58
  • possible duplicate of [Reference: Why does the PHP (or other server side) code in my Javascript not work?](http://stackoverflow.com/questions/13840429/reference-why-does-the-php-or-other-server-side-code-in-my-javascript-not-wor) – Quentin Apr 13 '14 at 21:53

2 Answers2

0

For a JSP scriptlet be able to use a value typed in a form field, you will have to send that value to the server in some way, given the fact that your server side Java code has no acess to what happens inside your form fields until you send the values. This means that document.getElementById('myTextArea').value will not work inside a JSP scriptlet block.

You could post the form and then use something like request.getParameter("fieldName") inside your JSP scriptlet block.

0

There is something you need to understand about the java in JSP's. It doesn't exist as far as the client side is concerned. All of the java code in a JSP is translated to a regular servlet. As far as the client side is concerned it's dealing with a standard html page. The only way for you to get client information to the JSP is the same with any other servlet.

user3056052
  • 1,387
  • 2
  • 13
  • 16