Rectangle 27 59

So you want to fire Ajax calls to the servlet? For that you need the XMLHttpRequest object in JavaScript. Here's a Firefox compatible example:

<script>
    var xhr = new XMLHttpRequest();
    xhr.onreadystatechange = function() {
        if (xhr.readyState == 4) {
            var data = xhr.responseText;
            alert(data);
        }
    }
    xhr.open('GET', 'myservlet', true);
    xhr.send(null);
</script>

This is however very verbose and not really crossbrowser compatible. For the best crossbrowser compatible way of firing ajaxical requests and traversing the HTML DOM tree, I recommend to grab jQuery. Here's a rewrite of the above in jQuery:

<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
    $.get('myservlet', function(data) {
        alert(data);
    });
</script>

Either way, the Servlet on the server should be mapped on an url-pattern of /myservlet (you can change this to your taste) and have at least doGet() implemented and write the data to the response as follows:

String data = "Hello World!";
response.setContentType("text/plain");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(data);

This should show Hello World! in the JavaScript alert.

You can of course also use doPost(), but then you should use 'POST' in xhr.open() or use $.post() instead of $.get() in jQuery.

Then, to show the data in the HTML page, you need to manipulate the HTML DOM. For example, you have a

<div id="data"></div>

in the HTML where you'd like to display the response data, then you can do so instead of alert(data) of the 1st example:

document.getElementById("data").firstChild.nodeValue = data;

In the jQuery example you could do this in a more concise and nice way:

$('#data').text(data);

To go some steps further, you'd like to have an easy accessible data format to transfer more complex data. Common formats are XML and JSON. The last one is most preferred since it's more concise and can be used in both Java and JavaScript on a very easy manner. In Java, you can use Google Gson to convert fullworthy Java objects to JSON and vice versa.

List<Product> products = productDAO.list(); // Product is just a Javabean with properties `id`, `name` and `description`.
String json = new Gson().toJson(products);
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(json);

In JavaScript you can use jQuery's $.getJSON() to get it "instantly". Let's display it in a <table>.

$.getJSON('myservlet', function(data) {
    var table = $('<table>').appendTo($('#data'));
    $.each(data, function(i, product) {
        var row = $('<tr>').appendTo(table);
        $('<td>').text(product.id).appendTo(row);
        $('<td>').text(product.name).appendTo(row);
        $('<td>').text(product.description).appendTo(row);
    });
});

I did what you said. But the servlet returns html code which is inside it as response. the alert(data) shows html code in browser's alert

using POST instead of GET worked.

calling a java servlet from javascript - Stack Overflow

java javascript ajax web-applications servlets
Rectangle 27 3

The code here will use AJAX to print text to an HTML5 document dynamically (Ajax code is similar to book Internet & WWW (Deitel)):

var asyncRequest;    
function start(){
    try
    {
        asyncRequest = new XMLHttpRequest();
        asyncRequest.addEventListener("readystatechange", stateChange, false);
        asyncRequest.open('GET', '/Test', true);    //   /Test is url to Servlet!
        asyncRequest.send(null);
    }
    catch(exception)
   {
    alert("Request failed");
   }
}

function stateChange(){
if(asyncRequest.readyState == 4 && asyncRequest.status == 200)
    {
    var text = document.getElementById("text");         //  text is an id of a 
    text.innerHTML = asyncRequest.responseText;         //  div in HTML document
    }
}

window.addEventListener("load", start(), false);
public class Test extends HttpServlet{
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws IOException{
        resp.setContentType("text/plain");
        resp.getWriter().println("Servlet wrote this! (Test.java)");
    }
}
<div id = "text"></div>

I wrote answer above when I was new with web programming. I let it stand, but the javascript part should definitely be in jQuery instead, it is 10 times easier than raw javascript.

calling a java servlet from javascript - Stack Overflow

java javascript ajax web-applications servlets
Rectangle 27 7

First create a Servlet class which returns the desired response based on the request. It can be HTML, XML or JSON. I'd suggest to use JSON for this since that's the most easiest produceable in Java and consumeable in JavaScript. You can use for example Google Gson to convert from a fullworthy Java object to a JSON string (and vice versa). E.g.

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOexception {
    // Populate response data somehow. Can be a String, Javabean or Collection/Map of either.
    Map<String, Object> data = new HashMap<String, Object>();
    data.put("success", true);
    data.put("message", "Hello World!");
    data.put("param", request.getParameter("foo"));
    
    // Write response data as JSON.
    response.setContentType("application/json");
    response.setCharacterEncoding("UTF-8");
    response.getWriter().write(new Gson().toJson(data));
}

Once the servlet is finished, just map it in web.xml the usual way. E.g. on an url-pattern of /firstServlet.

Then, in jQuery you can use use $.getJSON() to obtain JSON from the given resource. The first argument is the URL, which is obviously firstServlet. The second argument is the callback function wherein you can work on the returned response data. I've passed the request parameter foo for pure demonstration purposes, this is not mandatory.

$.getJSON('firstServlet?foo=bar', function(data) {
    alert('Success: ' + data.success + '\n'
        + 'Message: ' + data.message + '\n'
        + 'Param: ' + data.param);
});

You can of course do more with this than just displaying a simple alert. E.g. manupulating/traversing the HTML DOM in the current page based on the returned data.

I've posted two answers with practical examples before here, you may find it useful as well:

Calling a Servlet from a JSP page using jQuery Ajax - Stack Overflow

jquery jsp servlets
Rectangle 27 7

First create a Servlet class which returns the desired response based on the request. It can be HTML, XML or JSON. I'd suggest to use JSON for this since that's the most easiest produceable in Java and consumeable in JavaScript. You can use for example Google Gson to convert from a fullworthy Java object to a JSON string (and vice versa). E.g.

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOexception {
    // Populate response data somehow. Can be a String, Javabean or Collection/Map of either.
    Map<String, Object> data = new HashMap<String, Object>();
    data.put("success", true);
    data.put("message", "Hello World!");
    data.put("param", request.getParameter("foo"));
    
    // Write response data as JSON.
    response.setContentType("application/json");
    response.setCharacterEncoding("UTF-8");
    response.getWriter().write(new Gson().toJson(data));
}

Once the servlet is finished, just map it in web.xml the usual way. E.g. on an url-pattern of /firstServlet.

Then, in jQuery you can use use $.getJSON() to obtain JSON from the given resource. The first argument is the URL, which is obviously firstServlet. The second argument is the callback function wherein you can work on the returned response data. I've passed the request parameter foo for pure demonstration purposes, this is not mandatory.

$.getJSON('firstServlet?foo=bar', function(data) {
    alert('Success: ' + data.success + '\n'
        + 'Message: ' + data.message + '\n'
        + 'Param: ' + data.param);
});

You can of course do more with this than just displaying a simple alert. E.g. manupulating/traversing the HTML DOM in the current page based on the returned data.

I've posted two answers with practical examples before here, you may find it useful as well:

Calling a Servlet from a JSP page using jQuery Ajax - Stack Overflow

jquery jsp servlets
Rectangle 27 2

I solved it eventually by using a WebView that displays a HTML page, that uses the Dracula Graph Library. I transfer the data to the WebView by a Java function that was called from Javascript (on page load) that encoded the data as JSON. Not fancy, but it worked!

Displaying a graph (not charts) in an android app - Stack Overflow

android graph graph-layout
Rectangle 27 1

You can use a Ajax call to do it . Now when the HTML object is clicked call a java-script. Then in the JavaScript make a Ajax call to the servlet something like this

$.get("Query?ID="+id ,function(RespValue) 
         {


}

Here Query is my servlet mapping defined in web.xml and Id is the parameter i am passing you can sent multiple parameters too. and RespValue is the response value returned from the servlet. In the servelt write a do Get method and execute your java code. If you want to return some value use the function(RespValue) else remove it.

How to call a java method from a jsp when a html element is clicked? -...

java jsp
Rectangle 27 2

JS runs at the client machine. Java runs at the server machine. The only communication tool between those is HTTP. Java/JSP can generate/produce a HTML page and send it from server to client as a HTTP response, thus it can easily (pre)set Javascript variables by simply generating them as-is in the JSP template. But the other way round really requires a HTTP request from the client to the server. You can invoke HTTP requests synchronously by clicking a link or submitting a form, either manually or with little help of Javascript like link.click() or form.submit(). You can also invoke HTTP requests asynchronously with help of Ajaxical powers.

Long story short: let JS set it as a (hidden) input value / request parameter and send it to the server side by submitting the form with the (hidden) input value, or by invoking a link with the request parameter, or by firing an ajax request with a query string.

To learn more about the wall between Java/JSP and Javascript, you may find this article useful as well: Java/JSP/JSF and JavaScript.

Hope this clears a lot of things up and opens a new world for you.

Assigning values from JavaScript to Java variable - Stack Overflow

java javascript jsp jstl
Rectangle 27 2

URLs having ' in are perfectly valid. If you are outputting them to an HTML document without escaping, then the problem lies in your lack of HTML-escaping, not in the input checking. You need to ensure that you are calling an HTML encoding method every time you output any variable text (including URLs) into an HTML document.

Java does not have a built-in HTML encoder (poor show!) but most web libraries do (take your pick, or write it yourself with a few string replaces). If you use JSTL tags, you get escapeXml to do it for free by default:

<a href="<c:out value="${link}"/>">ok</a>

Whilst your main problem is HTML-escaping, it is still potentially beneficial to validate that an input URL is valid to catch mistakes - you can do that by parsing it with new URL(...) and seeing if you get a MalformedURLException.

You should also check that the URL begins with a known-good protocol such as http:// or https://. This will prevent anyone using dangerous URL protocols like javascript: which can lead to cross-site-scripting as easily as HTML-injection can.

javascript - how can I clean and sanitize a url submitted by a user fo...

java javascript html security
Rectangle 27 2

URLs having ' in are perfectly valid. If you are outputting them to an HTML document without escaping, then the problem lies in your lack of HTML-escaping, not in the input checking. You need to ensure that you are calling an HTML encoding method every time you output any variable text (including URLs) into an HTML document.

Java does not have a built-in HTML encoder (poor show!) but most web libraries do (take your pick, or write it yourself with a few string replaces). If you use JSTL tags, you get escapeXml to do it for free by default:

<a href="<c:out value="${link}"/>">ok</a>

Whilst your main problem is HTML-escaping, it is still potentially beneficial to validate that an input URL is valid to catch mistakes - you can do that by parsing it with new URL(...) and seeing if you get a MalformedURLException.

You should also check that the URL begins with a known-good protocol such as http:// or https://. This will prevent anyone using dangerous URL protocols like javascript: which can lead to cross-site-scripting as easily as HTML-injection can.

javascript - how can I clean and sanitize a url submitted by a user fo...

java javascript html security
Rectangle 27 12

  • The <head> tag is a HTML tag, which defines the head of the HTML page (this is where you define metadata, or include the resources such as JavaScript or CSS for example).
  • The <h:head> is a JSF tag (introduced with JSF 2.0) that handles the <head> part of your page. The interest of having such JSF tag is that this head becomes part of your JSF components tree, and thus, you can manipulate it in your Java code.

Regarding the <head> incompatibility with Primefaces, I don't see why it happens. Facelets introduced in JSF 1.x the ability to mix HTML code and JSF (XHTML) code, and you should not have any trouble to insert a HTML <head> tag in your page, even if you use Primefaces. Facelets is natively integrated with JSF 2.x.

org.w3c.dom.DOMException: HIERARCHY_REQUEST_ERR: An attempt was made to insert a node where it is not permitted.

There is a good reason PrimeFaces (amongst others) does not work well when an <head/> is used instead of an <h:head> See the other answer

jsf - What's the difference between and in Java Facele...

jsf facelets variant
Rectangle 27 12

  • The <head> tag is a HTML tag, which defines the head of the HTML page (this is where you define metadata, or include the resources such as JavaScript or CSS for example).
  • The <h:head> is a JSF tag (introduced with JSF 2.0) that handles the <head> part of your page. The interest of having such JSF tag is that this head becomes part of your JSF components tree, and thus, you can manipulate it in your Java code.

Regarding the <head> incompatibility with Primefaces, I don't see why it happens. Facelets introduced in JSF 1.x the ability to mix HTML code and JSF (XHTML) code, and you should not have any trouble to insert a HTML <head> tag in your page, even if you use Primefaces. Facelets is natively integrated with JSF 2.x.

org.w3c.dom.DOMException: HIERARCHY_REQUEST_ERR: An attempt was made to insert a node where it is not permitted.

There is a good reason PrimeFaces (amongst others) does not work well when an <head/> is used instead of an <h:head> See the other answer

jsf - What's the difference between and in Java Facele...

jsf facelets variant
Rectangle 27 14

You need to realize that Java/JSP is merely a HTML/CSS/JS code producer. So all you need to do is to just let JSP print the Java variable as if it is a JavaScript variable and that the generated HTML/JS code output is syntactically valid.

Provided that the Java variable is available in the EL scope by ${foo}, here are several examples how to print it:

<script>var foo = '${foo}';</script>
<script>someFunction('${foo}');</script>
<div onclick="someFunction('${foo}')">...</div>

Imagine that the Java variable has the value "bar", then JSP will ultimately generate this HTML which you can verify by rightclick, View Source in the webbrowser:

<script>var foo = 'bar';</script>
<script>someFunction('bar');</script>
<div onclick="someFunction('bar')">...</div>

Do note that those singlequotes are thus mandatory in order to represent a string typed variable in JS. If you have used var foo = ${foo}; instead, then it would print var foo = bar;, which may end up in "bar is undefined" errors in when you attempt to access it further down in JS code (you can see JS errors in JS console of browser's web developer toolset which you can open by pressing F12 in Chrome/FireFox23+/IE9+). Also note that if the variable represents a number or a boolean, which doesn't need to be quoted, then it will just work fine.

If the variable happens to originate from user-controlled input, then keep in mind to take into account XSS attack holes and JS escaping. Near the bottom of our EL wiki page you can find an example how to create a custom EL function which escapes a Java variable for safe usage in JS.

If the variable is a bit more complex, e.g. a Java bean, or a list thereof, or a map, then you can use one of the many available JSON libraries to convert the Java object to a JSON string. Here's an example assuming Gson.

String someObjectAsJson = new Gson().toJson(someObject);

Note that this way you don't need to print it as a quoted string anymore.

<script>var foo = ${someObjectAsJson};</script>

Hi @BalusC. I'm not sure what the OP means by "request object from the servlet". What do I need to do to have attributes in the request object?

Access Java / Servlet / JSP / JSTL / EL variables in JavaScript - Stac...

javascript jsp servlets parameter-passing el
Rectangle 27 3

Actually you can separate your application in to set of html files and java script files. What Single page application supposed to have is do all the application stuff without refreshing the browser. You can lazy load your views (html) and JavaScript whenever you need . I think you can start with a template or sample to get the idea of it. you can get more details from John Papa

Does it mean that a SPA is nothing else than using AJAX?

javascript - Is Single page application just one page using for entire...

javascript asp.net knockout.js single-page-application
Rectangle 27 2

You could use HTML/Javascript to get the input from the user and send it to a server with AJAX. Then on the server, you could execute the relevant Java based on what the user sent you.

Executing Java not in an applet sounds like it would be difficult to implement and a security risk.

Running a java .class program on an HTML page (not a JApplet) like in ...

java html eclipse java.util.scanner japplet
Rectangle 27 185

CTRL-click that brings you to where clicked object is defined works everywhere - not only in Java classes and variables in Java code, but in Spring configuration (you can click on class name, or property, or bean name), in Hibernate (you can click on property name or class, or included resource), you can navigate within one click from Java class to where it is used as Spring or Hibernate bean; clicking on included JSP or JSTL tag also works, ctrl-click on JavaScript variable or function brings you to the place it is defined or shows a menu if there are more than one place, including other .js files and JS code in HTML or JSP files.

Autocomplete in HSQL expressions, in Hibernate configuration (including class, property and DB column names), in Spring configuration

<property name="propName" ref="<hit CTRL-SPACE>"

and it will show you list of those beans which you can inject into that property.

Very smart autocomplete in Java code:

interface Person {
    String getName();
    String getAddress();
    int getAge();
}
//---
Person p;
String name = p.<CTRL-SHIFT-SPACE>

and it shows you ONLY getName(), getAddress() and toString() (only they are compatible by type) and getName() is first in the list because it has more relevant name. Latest version 8 which is still in EAP has even more smart autocomplete.

interface Country{
}
interface Address {
    String getStreetAddress();
    String getZipCode();
    Country getCountry();
}
interface Person {
    String getName();
    Address getAddress();
    int getAge();
}
//--- 
Person p;
Country c = p.<CTRL-SHIFT-SPACE>
Country c = p.getAddress().getCountry();

Smart autocomplete in JavaScript.

function Person(name,address) {
    this.getName = function() { return name };
    this.getAddress = function() { return address };
}

Person.prototype.hello = function() {
    return "I'm " + this.getName() + " from " + this.get<CTRL-SPACE>;
}

and it shows ONLY getName() and getAddress(), no matter how may get* methods you have in other JS objects in your project, and ctrl-click on this.getName() brings you to where this one is defined, even if there are some other getName() functions in your project.

Did I mention autocomplete and ctrl-clicking in paths to files, like <script src="", <img src="", etc?

Autocomplete in HTML tag attributes. Autocomplete in style attribute of HTML tags, both attribute names and values. Autocomplete in class attributes as well. Type <div class="<CTRL-SPACE> and it will show you list of CSS classes defined in your project. Pick one, ctrl-click on it and you will be redirected to where it is defined.

Latest version has language injection, so you can declare that you custom JSTL tag usually contains JavaScript and it will highlight JavaScript inside it.

<ui:obfuscateJavaScript>function something(){...}</ui:obfuscateJavaScript>

You can use Find Usages of any Java class or method and it will find where it is used including not only Java classes but Hibernate, Spring, JSP and other places. Rename Method refactoring renames method not only in Java classes but anywhere including comments (it can not be sure if string in comments is really method name so it will ask). And it will find only your method even if there are methods of another class with same name. Good source control integration (does SVN support changelists? IDEA support them for every source control), ability to create a patch with your changes so you can send your changes to other team member without committing them.

When I look at HashMap in debugger's watch window, I see logical view - keys and values, last time I did it in Eclipse it was showing entries with hash and next fields - I'm not really debugging HashMap, I just want to look at it contents.

It validates Spring and Hibernate configuration right when you edit it, so I do not need to restart server to know that I misspelled class name, or added constructor parameter so my Spring cfg is invalid.

Last time I tried, I could not run Eclipse on Windows XP x64.

and it will suggest you person.name or person.address. Ctrl-click on person.name and it will navigate you to getName() method of Person class.

Type Pattern.compile(""); put \\ there, hit CTRL-SPACE and see helpful hint about what you can put into your regular expression. You can also use language injection here - define your own method that takes string parameter, declare in IntelliLang options dialog that your parameter is regular expression - and it will give you autocomplete there as well. Needless to say it highlights incorrect regular expressions.

There are few features which I'm not sure are present in Eclipse or not. But at least each member of our team who uses Eclipse, also uses some merging tool to merge local changes with changes from source control, usually WinMerge. I never need it - merging in IDEA is enough for me. By 3 clicks I can see list of file versions in source control, by 3 more clicks I can compare previous versions, or previous and current one and possibly merge.

It allows to to specify that I need all .jars inside WEB-INF\lib folder, without picking each file separately, so when someone commits new .jar into that folder it picks it up automatically.

Mentioned above is probably 10% of what it does. I do not use Maven, Flex, Swing, EJB and a lot of other stuff, so I can not tell how it helps with them. But it does.

The two examples about auto-completing java code work identically in eclipse. Could someone with more rep delete just the java examples please?

Most of your examples are available in Eclipse, either directly or via 3rd party plugins. I know of no one who uses an external tool for svn merge in Eclipse. For spring/hibernate/javascript editors (and autocomplete) there are 3rd party plugins. As for regex and jsp EL, you beat me :)

The Jboss Tools plugin adds autocomplete of Hibernate and JSF expressions.

For the eclipse debugging view there is an option to show the contents of the collections rather than the implementation details. For lists and sets, it'll show their contents. For maps, it'll show a list of key-value pairs. It's also possible to set custom displays up.

java - Things possible in IntelliJ that aren't possible in Eclipse? - ...

java eclipse ide intellij-idea
Rectangle 27 185

CTRL-click that brings you to where clicked object is defined works everywhere - not only in Java classes and variables in Java code, but in Spring configuration (you can click on class name, or property, or bean name), in Hibernate (you can click on property name or class, or included resource), you can navigate within one click from Java class to where it is used as Spring or Hibernate bean; clicking on included JSP or JSTL tag also works, ctrl-click on JavaScript variable or function brings you to the place it is defined or shows a menu if there are more than one place, including other .js files and JS code in HTML or JSP files.

Autocomplete in HSQL expressions, in Hibernate configuration (including class, property and DB column names), in Spring configuration

<property name="propName" ref="<hit CTRL-SPACE>"

and it will show you list of those beans which you can inject into that property.

Very smart autocomplete in Java code:

interface Person {
    String getName();
    String getAddress();
    int getAge();
}
//---
Person p;
String name = p.<CTRL-SHIFT-SPACE>

and it shows you ONLY getName(), getAddress() and toString() (only they are compatible by type) and getName() is first in the list because it has more relevant name. Latest version 8 which is still in EAP has even more smart autocomplete.

interface Country{
}
interface Address {
    String getStreetAddress();
    String getZipCode();
    Country getCountry();
}
interface Person {
    String getName();
    Address getAddress();
    int getAge();
}
//--- 
Person p;
Country c = p.<CTRL-SHIFT-SPACE>
Country c = p.getAddress().getCountry();

Smart autocomplete in JavaScript.

function Person(name,address) {
    this.getName = function() { return name };
    this.getAddress = function() { return address };
}

Person.prototype.hello = function() {
    return "I'm " + this.getName() + " from " + this.get<CTRL-SPACE>;
}

and it shows ONLY getName() and getAddress(), no matter how may get* methods you have in other JS objects in your project, and ctrl-click on this.getName() brings you to where this one is defined, even if there are some other getName() functions in your project.

Did I mention autocomplete and ctrl-clicking in paths to files, like <script src="", <img src="", etc?

Autocomplete in HTML tag attributes. Autocomplete in style attribute of HTML tags, both attribute names and values. Autocomplete in class attributes as well. Type <div class="<CTRL-SPACE> and it will show you list of CSS classes defined in your project. Pick one, ctrl-click on it and you will be redirected to where it is defined.

Latest version has language injection, so you can declare that you custom JSTL tag usually contains JavaScript and it will highlight JavaScript inside it.

<ui:obfuscateJavaScript>function something(){...}</ui:obfuscateJavaScript>

You can use Find Usages of any Java class or method and it will find where it is used including not only Java classes but Hibernate, Spring, JSP and other places. Rename Method refactoring renames method not only in Java classes but anywhere including comments (it can not be sure if string in comments is really method name so it will ask). And it will find only your method even if there are methods of another class with same name. Good source control integration (does SVN support changelists? IDEA support them for every source control), ability to create a patch with your changes so you can send your changes to other team member without committing them.

When I look at HashMap in debugger's watch window, I see logical view - keys and values, last time I did it in Eclipse it was showing entries with hash and next fields - I'm not really debugging HashMap, I just want to look at it contents.

It validates Spring and Hibernate configuration right when you edit it, so I do not need to restart server to know that I misspelled class name, or added constructor parameter so my Spring cfg is invalid.

Last time I tried, I could not run Eclipse on Windows XP x64.

and it will suggest you person.name or person.address. Ctrl-click on person.name and it will navigate you to getName() method of Person class.

Type Pattern.compile(""); put \\ there, hit CTRL-SPACE and see helpful hint about what you can put into your regular expression. You can also use language injection here - define your own method that takes string parameter, declare in IntelliLang options dialog that your parameter is regular expression - and it will give you autocomplete there as well. Needless to say it highlights incorrect regular expressions.

There are few features which I'm not sure are present in Eclipse or not. But at least each member of our team who uses Eclipse, also uses some merging tool to merge local changes with changes from source control, usually WinMerge. I never need it - merging in IDEA is enough for me. By 3 clicks I can see list of file versions in source control, by 3 more clicks I can compare previous versions, or previous and current one and possibly merge.

It allows to to specify that I need all .jars inside WEB-INF\lib folder, without picking each file separately, so when someone commits new .jar into that folder it picks it up automatically.

Mentioned above is probably 10% of what it does. I do not use Maven, Flex, Swing, EJB and a lot of other stuff, so I can not tell how it helps with them. But it does.

The two examples about auto-completing java code work identically in eclipse. Could someone with more rep delete just the java examples please?

Most of your examples are available in Eclipse, either directly or via 3rd party plugins. I know of no one who uses an external tool for svn merge in Eclipse. For spring/hibernate/javascript editors (and autocomplete) there are 3rd party plugins. As for regex and jsp EL, you beat me :)

The Jboss Tools plugin adds autocomplete of Hibernate and JSF expressions.

For the eclipse debugging view there is an option to show the contents of the collections rather than the implementation details. For lists and sets, it'll show their contents. For maps, it'll show a list of key-value pairs. It's also possible to set custom displays up.

java - Things possible in IntelliJ that aren't possible in Eclipse? - ...

java eclipse ide intellij-idea
Rectangle 27 185

CTRL-click that brings you to where clicked object is defined works everywhere - not only in Java classes and variables in Java code, but in Spring configuration (you can click on class name, or property, or bean name), in Hibernate (you can click on property name or class, or included resource), you can navigate within one click from Java class to where it is used as Spring or Hibernate bean; clicking on included JSP or JSTL tag also works, ctrl-click on JavaScript variable or function brings you to the place it is defined or shows a menu if there are more than one place, including other .js files and JS code in HTML or JSP files.

Autocomplete in HSQL expressions, in Hibernate configuration (including class, property and DB column names), in Spring configuration

<property name="propName" ref="<hit CTRL-SPACE>"

and it will show you list of those beans which you can inject into that property.

Very smart autocomplete in Java code:

interface Person {
    String getName();
    String getAddress();
    int getAge();
}
//---
Person p;
String name = p.<CTRL-SHIFT-SPACE>

and it shows you ONLY getName(), getAddress() and toString() (only they are compatible by type) and getName() is first in the list because it has more relevant name. Latest version 8 which is still in EAP has even more smart autocomplete.

interface Country{
}
interface Address {
    String getStreetAddress();
    String getZipCode();
    Country getCountry();
}
interface Person {
    String getName();
    Address getAddress();
    int getAge();
}
//--- 
Person p;
Country c = p.<CTRL-SHIFT-SPACE>
Country c = p.getAddress().getCountry();

Smart autocomplete in JavaScript.

function Person(name,address) {
    this.getName = function() { return name };
    this.getAddress = function() { return address };
}

Person.prototype.hello = function() {
    return "I'm " + this.getName() + " from " + this.get<CTRL-SPACE>;
}

and it shows ONLY getName() and getAddress(), no matter how may get* methods you have in other JS objects in your project, and ctrl-click on this.getName() brings you to where this one is defined, even if there are some other getName() functions in your project.

Did I mention autocomplete and ctrl-clicking in paths to files, like <script src="", <img src="", etc?

Autocomplete in HTML tag attributes. Autocomplete in style attribute of HTML tags, both attribute names and values. Autocomplete in class attributes as well. Type <div class="<CTRL-SPACE> and it will show you list of CSS classes defined in your project. Pick one, ctrl-click on it and you will be redirected to where it is defined.

Latest version has language injection, so you can declare that you custom JSTL tag usually contains JavaScript and it will highlight JavaScript inside it.

<ui:obfuscateJavaScript>function something(){...}</ui:obfuscateJavaScript>

You can use Find Usages of any Java class or method and it will find where it is used including not only Java classes but Hibernate, Spring, JSP and other places. Rename Method refactoring renames method not only in Java classes but anywhere including comments (it can not be sure if string in comments is really method name so it will ask). And it will find only your method even if there are methods of another class with same name. Good source control integration (does SVN support changelists? IDEA support them for every source control), ability to create a patch with your changes so you can send your changes to other team member without committing them.

When I look at HashMap in debugger's watch window, I see logical view - keys and values, last time I did it in Eclipse it was showing entries with hash and next fields - I'm not really debugging HashMap, I just want to look at it contents.

It validates Spring and Hibernate configuration right when you edit it, so I do not need to restart server to know that I misspelled class name, or added constructor parameter so my Spring cfg is invalid.

Last time I tried, I could not run Eclipse on Windows XP x64.

and it will suggest you person.name or person.address. Ctrl-click on person.name and it will navigate you to getName() method of Person class.

Type Pattern.compile(""); put \\ there, hit CTRL-SPACE and see helpful hint about what you can put into your regular expression. You can also use language injection here - define your own method that takes string parameter, declare in IntelliLang options dialog that your parameter is regular expression - and it will give you autocomplete there as well. Needless to say it highlights incorrect regular expressions.

There are few features which I'm not sure are present in Eclipse or not. But at least each member of our team who uses Eclipse, also uses some merging tool to merge local changes with changes from source control, usually WinMerge. I never need it - merging in IDEA is enough for me. By 3 clicks I can see list of file versions in source control, by 3 more clicks I can compare previous versions, or previous and current one and possibly merge.

It allows to to specify that I need all .jars inside WEB-INF\lib folder, without picking each file separately, so when someone commits new .jar into that folder it picks it up automatically.

Mentioned above is probably 10% of what it does. I do not use Maven, Flex, Swing, EJB and a lot of other stuff, so I can not tell how it helps with them. But it does.

The two examples about auto-completing java code work identically in eclipse. Could someone with more rep delete just the java examples please?

Most of your examples are available in Eclipse, either directly or via 3rd party plugins. I know of no one who uses an external tool for svn merge in Eclipse. For spring/hibernate/javascript editors (and autocomplete) there are 3rd party plugins. As for regex and jsp EL, you beat me :)

The Jboss Tools plugin adds autocomplete of Hibernate and JSF expressions.

For the eclipse debugging view there is an option to show the contents of the collections rather than the implementation details. For lists and sets, it'll show their contents. For maps, it'll show a list of key-value pairs. It's also possible to set custom displays up.

java - Things possible in IntelliJ that aren't possible in Eclipse? - ...

java eclipse ide intellij-idea
Rectangle 27 4

You seem to fail to grasp the fact that in the context of Java/JSF, all the HTML, CSS and JavaScript code are merely plain vanilla Strings and you seem to expect that HTML/CSS/JS somehow magically runs inside Java/JSF code. This is not true. Java/JSF is a HTML/CSS/JS code producer, not executor. The webbrowser retrieves them all as one big String and then parses and executes it.

If you want to invoke a JS function with parameters supplied, like so when you would do in real JS code:

handleResize(500, 300);

And you have those values as Java variables, then you just need to make sure that you write Java code in such way that exactly the above String is produced (again, this is just Java code, no JS code):

String call = "handleResize(" + w + ", " + h + ")";

You can verify beforehand by printing it to the stdout/logger:

System.out.println(call);

It must print exactly the desired valid JS function call syntax handleResize(500, 300);.

If it does, then just pass that unmodified to RequestContext#execute().

RequestContext.getCurrentInstance().execute(call);

Invoking parameterised function of javascript from managed bean in jsf...

javascript jsf primefaces javabeans
Rectangle 27 2

As Marko pointed out, you might need to read some more about the client/server separation in web programming. If you want a framework to help you do remote Java invocation from Javascript, have a look at DWR.

How to call a java method from a jsp when a html element is clicked? -...

java jsp
Rectangle 27 23

JavaScript is an object-oriented scripting language that allows you to create dynamic HTML pages, allowing you to process input data and maintain data, usually within the browser.

Java is a programming language, core set of libraries, and virtual machine platform that allows you to create compiled programs that run on nearly every platform, without distribution of source code in its raw form or recompilation.

While the two have similar names, they are really two completely different programming languages/models/platforms, and are used to solve completely different sets of problems.

Also, this is directly from the Wikipedia Javascript article:

A common misconception is that JavaScript is similar or closely related to Java; this is not so. Both have a C-like syntax, are object-oriented, are typically sandboxed and are widely used in client-side Web applications, but the similarities end there. Java has static typing; JavaScript's typing is dynamic (meaning a variable can hold an object of any type and cannot be restricted). Java is loaded from compiled bytecode; JavaScript is loaded as human-readable code. C is their last common ancestor language.

Javascript isn't just for HTML pages, Java6 now includes it, BIRT uses it for report scripting - I'm sure that there are other non-HTML uses beyond these two.

You're right. With the development of Rhino, and some of the other developments you mentioned, Javascript has come pretty far out of the browser sandbox.

Scripting is simply one particular kind of programming... instead you should say perhaps that Java is a compiled programming language and javascript is a scripting or interpreted programming language.

What's the difference between JavaScript and Java? - Stack Overflow

java javascript