aspose file tools*
The moose likes JSP and the fly likes JavaScript variables in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "JavaScript variables in JSP" Watch "JavaScript variables in JSP" New topic
Author

JavaScript variables in JSP

Wayne Burr
Ranch Hand

Joined: Oct 15, 2002
Posts: 38
I'm having no luck in passing a JavaScript varable in JSP. I'm sure that it is simple but nothing is working for me.
Here is a sample of the code that I am using:
..
..
..
var inxfind = factdtl.search("-")
var strinx = factdum.slice(0,inxfind)
<% FactorLME currentFactor = new FactorLME();
String factDate = currentFactor.getstartDate();
%>
<%
factorLMEList = connector.getFactorLMEs();
session.setAttribute("factorLMEList", factorLMEList);
currentFactor = factorLMEList.getFactorLMEs([I]strinx{/I]);
%>
..
..
..
Any idea would be great!
Thanks in advance!
Wayne Burr
Ranch Hand

Joined: Oct 15, 2002
Posts: 38
This is the error that I receive:
org.apache.jasper.JasperException: Unable to compile class for JSPNote: sun.tools.javac.Main has been deprecated.
C:\Tomcat\work\localhost_8080%2Fka\_0002fjsp_0002fFactors_0002ejspFactors_jsp_363.java:133: Undefined variable: strinx
currentFactor = factorLMEList.getFactorLMEs((int)strinx);
^
--Hope this helps to give ya ideas to help me--
Wayne Burr
Ranch Hand

Joined: Oct 15, 2002
Posts: 38
the above error was from trying something else. Here is the one that goes with the code from above.
currentFactor = factorLMEList.getFactorLMEs(strinx);
Richard Vagner
Ranch Hand

Joined: Jun 26, 2001
Posts: 107
I don't think you can! You are mixing up server side code with client side code. JSP is on the server side and java script is on the client side
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Wayne, Richard is right. The JSP is all compiled and interpreted before the HTML and JavaScript is sent to the browser. The only way to get a Javascript value to the JSP for processing is to make a round trip to the server.
If the value is something that is coming from user input you canuse javascript to process it, check it for validity or whatever it needs to do client side then store the reulst ot be used as a hidden variable (or write it to the URL) for the JSP to use.
hope that helps


Dave
Wayne Burr
Ranch Hand

Joined: Oct 15, 2002
Posts: 38
Thanks for the reply! --
I am still pretty new to JAVA and JSP etc, but I can't understand why a variable cannot be created and passed between JavaScript and JSP. I'm intermixing HTML and JSP variables.
I do understand the concept of Client and Server side processing, but if you can intermix code, why can't you do the same with variables?
Wayne Burr
Ranch Hand

Joined: Oct 15, 2002
Posts: 38
I was writing a response to Richard's reply when Dave's reply came in.
Thanks for the replies. Looks as I will have to find another solution to what I was trying to accomplish.
Thanks again!
Wayne Burr
Ranch Hand

Joined: Oct 15, 2002
Posts: 38
I'm going to try to stay on the same post with my new problem to do what I really want to do. (Which is not working the way I was hoping)
With the above replies and ideas I tried to do the following with a "input type=hidden name=hinx value=0" field:

I do get the following error:
java.lang.NumberFormatException: null
at java.lang.Integer.parseInt(Integer.java:394)
at java.lang.Integer.parseInt(Integer.java:476)
With all my research that I have done and testing I am unable to find if you can setup JAVA objects in JAVASCRIPT (using IE).
Thanks in advance again...
Richard Vagner
Ranch Hand

Joined: Jun 26, 2001
Posts: 107
Write two separate programs. One for html code one for jsp code. In the form for the html code,
do something like this:
<form name="xxx" method="post" action="A.jsp">
In A.jsp, include your jsp code.
Hope this helps
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JavaScript variables in JSP