How can I pass a variable to a JSP class using a url?

I am trying to modify someone's written JavaScript code to pass a URL variable (called by the manufacturer) to a Java class. Interestingly, the file is an HTML file with JavaScript. Since I'm new to JSP, I'm not even sure if it 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 am trying to pass a link url

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

and pass the value back to the page where the class will hopefully be raised.
I added a 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 a function Table()

. I'm more familiar with PHP and these files usually have a PHP extension, but in this case, the source file uses HTML to pass the variable to the Java class QWMASMatch

with just an else clause. Any ideas what I might be doing wrong?

The script seems to still resolve the else clause when I try to simply type

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

early

+1


source to share


1 answer


If this value has a forward slash? \ QWMASMatch

It looks a bit like server side code that mixes with JS here:

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

      



You may have intended:

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

      

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

0


source







All Articles