Skip to main content

Posts

Showing posts with the label j2ee

passing attributes in nested tiles

Tiles is a great framework to organize site content by constructing a page using multiple tiles. It allows reuse and customization of site content. I ran into a problem of making tiles attribute visible to a nested tile. The attributes defined in tiles definitions are defined in tiles scope and hence only available to the tile associated with the definition. In order to make the attribute available to nested tiles, pass the attribute as follows; <tiles:insert attribute="header" ignore="true"> <tiles:put name="title" beanName="title" beanScope="tile"/> </tiles:insert> If there is a need to access the attribute in struts bean tags or JSTL use <tiles:useAttribute/> or <tiles:importAttribute/> tags in jsp to access the attribute as follows; <tiles:useAttribute name="title" /> You can now access the value of title attribute using struts bean tag <bean:write name="title" /> or usin...

Password protecting tomcat web application

Following configuration in web.xml of a web application is useful for password protecting the web application in tomcat servlet engine. <security-constraint> <web-resource-collection> <web-resource-name>portalBase Application</web-resource-name> <url-pattern>/*</url-pattern> <!-- If you list http methods, only those methods are protected --> <http-method>DELETE</http-method> <http-method>GET</http-method> <http-method>POST</http-method> <http-method>PUT</http-method> </web-resource-collection> <auth-constraint> <role-name>role1</role-name> </auth-constraint> </security-constraint> <login-config> <auth-method>BASIC</auth-method> <realm-name>portalBase Application</realm-name> </login-config> <!-- Security roles referenced by this ...

Restrict access to IPs in Tomcat

Add following valve to tomcat server.xml to restrict access to the website from limited IPs. <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="127.0.0.1,xx.xxx.xxx.xx,xxx.xx.xxx.[6789].,xxx.xx.xx.xx.*,xxx.xx.xx.x[2345]., xxx.xx.xx.xx[4578]"/>

Web Application specific Configuration

I was looking for a way to easily manage web application specific configuration in separate properties file. In our current version of application, a properties file was included in a war file of web application. However, this was problematic since the properties file had to be updated every time we deployed a new war file. I tried passing the name of the properties file in Tomcat command-line but that did not work well for multiple web applications. Then I came across Environment tags in Tomcat context definition that can be configured for each individual application. So I decided to us the following solution. 1. Add Environment entry for name of a properties file in context definition of web application. <Context path="/app1" docBase="C:/app1/web-dir" debug="0" reloadable="true"> <Environment name="appconfig" value="WebApp1.properties" type="java.lang.String" overri...