• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JavaScript variables in JSP

 
Wayne Burr
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Wayne Burr
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic