[Java] Spring use DAO in JSP page

So you're happily coding your webapp with Spring, and have all your DAOs correctly defined as beans; you know they work because you are constantly injecting them around, but now you need to access one of them from a JSP.. how?

You may find this code fragment useful:

 <%@page import="com.groglogs.mydaos.MyDao"%>  
 <%@page import="org.springframework.web.context.WebApplicationContext"%>  
 <%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>  
 MyDao myDao = null;  
 WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(getServletContext());  
 if (context != null) {  
   myDao = (MyDao) context.getBean("myDao");  

You import your DAO, and request it directly from the JSP. Note that this example relies on the fact that somewhere you have correctly defined a bean named "myDao".


[Eclipse] Comparison method violates its general contract error when updating

When installing updates in Eclipse, you may encounter the "Comparison method violates its general contract" error.

This may be related to a known bug in older Eclipse versions when using new JDKs (>6), I encountered it even using a JDK6 with latest Helios though. To fix it, try adding:


in your eclipse.ini file, after the -vmargs flag, then restart Eclipse and run the update manager again.

[Eclipse] Slow update process

When installing updates via the Eclipse update manager, it sometimes takes forever to complete the update process, even for very small updates.

One cause may be Eclipse trying to contact all known sites when fetching updates. To avoid that, try adding:


in your eclipse.ini file, after the -vmargs flag then restart Eclipse. Alternatively, you can uncheck the "Contact all update sites" flag every time you run an update from the update wizard.


[Windows] Manage printers from command line

On Windows, you can manage the printers connected to your computer from the command line either via Rundll32 printui.dll,PrintUIEntry on 32-bit systems or Cscript.exe and the Prnmngr.vbs script on 64-bit systems.