Social Icons

Showing posts with label JSP/ Servlet. Show all posts
Showing posts with label JSP/ Servlet. Show all posts

Identify from which JAR file the class was loaded

It's a very common situation that Java developers, especially web developers face in day to day work field that a class with same name exists in two different JAR files even sometimes with same package name. A classic example is logger classes or servlet / jsp related classes, or when libraries from server gets loaded first ignoring the application's library set.

While we all know the remedy is to remove the conflicting JAR file but it becomes cumbersome to determine from what location the offending class is getting loaded.

To solve this we present you the simple java code which you can run as a JSP page, or a Servlet or standalone code by modifying accordingly and determine the path as well as the JAR from which the offending version of the class is getting loaded.



Note that you just need to edit the fully qualified class name to get the details.
The code is pretty self explanatory and hope doesn't needs any further explanation.


Thank you for visiting techjawab.com, feel free to post your comments back!

Dynamic menu with Sitemesh

It's always a matter of concern for web developers to keep the page design constant across all of the application. Using frames is a dead idea, so what's left including your header, navigation and footer jsp on each and every page ?

Well there is something better than that, Sitemesh. It allows you to keep your page design consistent or even maintaining different UI styles for different parts of the site.


But a major problem which Sitemesh users often come across is to implement a dynamic menu / navigation, like in a situation where menus in your application changes based on the 'role' of the logged in user. The solution for the same is here implemented in a simple JSP / Servlet code.


Dynamic menu with Sitemesh


To keep a dynamic approach, I have kept Menu texts and links in a properties file.

Downloads:
sitemesh-2.4.2.jar - http://wiki.sitemesh.org/display/sitemesh/Download

Logic:
The basic idea is once the user logs into the application, the user's role is stored into the application session. The sitemesh reads the user role and applies appropriate navigation menus based on the role. Secondly to highlight the menu item which is currently selected a meta tag is placed on each page just to denote under when menu item it belongs. The sitemesh decorator reads the same meta tag and applies a different css to it's menu item.


web.xml - Configure the sitemesh filter to intercept request and send for decoration



decorators.xml - sitemesh config file for defining decorators



main.jsp - decorator, the place where you design the layout of your design and implement the dynamic logic. The code below is pretty self-explainatory with the logic stated above.



Download




Download the MyEclipse / Eclipse project SiteMeshDynamicMenu.zip




Hope these tips helped you, don't forget to leave your comments here.