tags:

views:

285

answers:

1

I'm trying to modify someone's written JavaScript code to pass a URL variable (called manufacturer) into a Java class. The interesting thing is the file is an HTML file with JavaScript. Because I'm new to JSP, I'm not even sure if this can be done but here is the HTML/JavaScript code:

<html>
<head>
<script type="text/javascript">
var url = "\QWMASMatch"; // The server-side script

function Table(){
 var currentTime=new Date();
 var ele = document.getElementById('Table'); 
 function handleHttpResponse()
  {
   if (http.readyState == 4) {
      ele.innerHTML = http.responseText;
    }
  }
 var http = getHTTPObject(); // We create the HTTP Object
 var tempUrl = url;
 String manufacturer = request.getParameter("manufacturer");
 if ( manufacturer != null && !manufacturer.equals(""))
 {
 http.open("GET", tempUrl+"?"+"manufacturer="+manufacturer, true);
 http.onreadystatechange = handleHttpResponse;
 http.send(null);
 } else {
 http.open("GET", tempUrl+"?"+"Time="+currentTime, true);
 http.onreadystatechange = handleHttpResponse;
 http.send(null);
 }
}

function getHTTPObject(){
 var xmlhttp;
 /*@cc_on
 @if (@_jscript_version >= 5)
   try {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
   }catch (e){
    try {
     xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
     }catch (E) {
      xmlhttp = false;
      }
  }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
 }

</script>
</head>
<body>
<img src='enet.jpg'>
<div class='title'>
QuoteWerks-2-MAS</div>
<div id="Table">Loading . . . </div>
<script type="text/javascript">
Table()</script>
</body>
</html>

I'm trying to pass a url link

http://localhost/QWMASMatch.html?manufacturer=ADOBE

and pass the value back into the page where it is hopefully picked up by the class.
I added the segment

 String manufacturer = request.getParameter("manufacturer");
 if ( manufacturer != null && !manufacturer.equals(""))
 {
 http.open("GET", tempUrl+"?"+"manufacturer="+manufacturer, true);
 http.onreadystatechange = handleHttpResponse;
 http.send(null);
 } else {
 http.open("GET", tempUrl+"?"+"Time="+currentTime, true);
 http.onreadystatechange = handleHttpResponse;
 http.send(null);

}

...in the Table() function. I'm more familiar with PHP, and those files usually have a PHP extension however in this case, the original file is using HTML to pass a variable into a Java QWMASMatch class with just the else clause. Any ideas what I could be doing wrong?

The script seems to still be resolving to the else clause when I attempt to just type in

http://localhost/QWMASMatch.html?manufacturer=ADOBE

thanks in advance

A: 

Should this value have a forward slash? \QWMASMatch

It looks a bit like the server-side code is getting mixed in with the JS here:

String manufacturer = request.getParameter("manufacturer");

Perhaps you intended:

var manufacturer = '<% out.println(request.getParameter("manufacturer")); %>';

...using <% %> to tell JSP to execute the contained code on the server.

steamer25
does apache tomcat automatically know to execute the java code between the delimiters in the html file?
phill
the slash "\" is correct. it works with it in there. As a newbie, I don't completely understand why yet either. I think it has to do with servlet mapping
phill
No, you'd have to make it a JSP. Then Tomcat will process Java code between <% %> tags on the server side.
steamer25