0
**<%@ page import="com.ampliflex.commons.Ampliflex" %>**
<html>
<head>
<title>Search Result  </title>

<style>
img{ height: 150px; float: left; border: 3;}
div{font-size:10pt; margin-right:150px;
margin-left:150px; }
</style>
 <script type="text/javascript" src="jquery-1.6.1.js"></script>
 <script type="text/javascript">
$(document).ready(function(){
  **Ampliflex ms = Ampliflex.getInstance();
  String mailHost = ms.getMailServer();**
// This function get the search results from Solr server 
    $("#submit").click(function(){
        var query=getquerystring() ; //get the query string entered by user

Here in this, I imported a java class and instantiate its object. but object is not visible and script is generating an error "missing ; before statement Ampliflex ms = Ampliflex.getInstance(); "...i am not getting why so.

EDIT:

The problem is i need to access this mailHost with in javascript. if i instantiate object with in <%.. %> then mailHost is local variable and am not able to access in javascript tag. is there any solution for it.

2
  • 1
    you're trying to instantiate a server side Object from the client side, JS. think about it again. Commented Jun 17, 2011 at 5:21
  • 1
    Where (and when) does the Java run? Where (and when) does the JavaScript run? Therein lies the answer. The server-side Java scriptlet tags can emit JavaScript code. However, the scriptlets run before the HTML is sent to the client. Commented Jun 17, 2011 at 5:27

2 Answers 2

2

You are trying to instantiate java object but, without a scriptlet

it should be some thing like

<%

  Ampliflex ms = Ampliflex.getInstance();
  String mailHost = ms.getMailServer();
%>

$(document).ready(function(){ //Mail host var mailHost='<%= mailHost %>';

// This function get the search results from Solr server $("#submit").click(function(){ var query=getquerystring() ;

And, if you want to invoke method after page is loaded, try using ajax.

Sign up to request clarification or add additional context in comments.

3 Comments

is it not possible to instantiate object with in java script tag??
You cannot invoke directly ! You need to use applet or send a request to server !
The problem is i need to access this mailHost with in javascript. if i instantiate object with in <%.. %> then mailHost is local variable and am not able to access in javascript tag. is there any solution for it.
1

Problem here is this line:

Ampliflex ms = Ampliflex.getInstance();

  String mailHost = ms.getMailServer();

This is actually Java code. This cannot execute on client side. Use scriptlet tags.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.