J2EE

CORS Filter for J2EE Application

j2ee

CORS (Cross-origin resource sharing) helps in making Javascript based AJAX request from one domain to another, requesting domain is different from the domain where the request is made. This type of request is by default forbidden at the browser level and if this type of requet is made without proper settings, they will result in some origin security policy error. ... Read More »

Some useful JSP Expression Language hacks in JSP

j2ee

Some useful JSP Expression Language hacks in JSP If you have JSTL in your classpath(by including JSTL.jar and standard.jar in your classpath), then you need to write below taglib directive so that you can use JSTL tags. <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%/> 1. Redirecting to other resource in application <c:redirect url="/hello.html"/> where, hello.html is another resource. 2. Looping model data in ... Read More »

How to configure sessioncookie at Tomcat server level OR at Application level (web.xml)

How to configure session cookie at Tomcat server level or at Application level (web.xml) In this post we will see how to configure session cookie at Tomcat server level or at application level using web.xml You can use either way to set a cookie. Tomcat server Go to -> conf directory -> open context.xml -> add below lines:- <Context sessionCookieName="<yourCookieName>" ... Read More »

Anti cross-site scripting (XSS) filter for Java web applications

j2ee

XSS (cross-site scripting)is the most prevalent web application security flaw. XSS flaws occur when an application includes user supplied data in a page sent to the browser without properly validating or escaping that content. Detection of most XSS flaws is fairly easy via testing or code analysis. How Do I Prevent ‘Cross-Site Scripting (XSS)’? HTML escaping Escaping of Input Escaping ... Read More »

Create a J2EE Web Application project with Apache Maven

apache

In this tutorial, we will learn how to create a J2EE Web Application project with Apache Maven, imports it into the Eclipse IDE, and package the Java project into a war file. Tools used : Maven 3.2.5 (For how to install, click here) Eclipse (Kepler Release) JDK 7 A. Create a Java Project from Maven Template In a terminal (*uix ... Read More »

Installing Apache Maven on Ubuntu & Windows

apache

To install Apache Maven on Ubuntu and Windows machine we need to take the following steps- Download the current stable version of Maven from http://maven.apache.org/download.cgi. Once downloaded follow the istallation steps – Installation Instructions A. Unix-based Operating Systems (Linux, Solaris and Mac OS X) Extract the distribution archive, i.e. apache-maven-3.2.5-bin.tar.gz to the directory you wish to install Maven 3.2.5. These ... Read More »

How to handle jQuery cross domain AJAX request

Cross Domain jQuery AJAX request AJAX Requests are only possible if port, protocol and domain of sender and receiver are equal, means that the following below listed requests won’t work- Requesting https://serverA.com/a.php from http://serverA.com/b.php Requesting http://subdomain.serverA.com from http://serverA.com Requesting http://serverA.com:5000 from http://serverA.com Here in this tutorial we will cover the ways to handle this restriction. First lets look at the ... Read More »

How to handle HTTP error 414 Request-URI Too Long

apache

Typically Web servers set fairly generous limits on length for URL query string e.g. up to 2048 or 4096 characters. While running a web application in Tomcat & HTTP Apache server, we came across a situation where we were asked to handle an extremely long URL query strings. Which was throwing HTTP 414 “Request-URI Too Long” error. For this situation ... Read More »

Java HttpServletRequest get current URL in browsers URL bar

j2ee

If your current request is coming from an “inside the app-server” forward or include, the app-server is expected to preserve request information as request attributes. The specific attributes, and what they contain, depends on whether you’re doing a forward or an include. For , the original parent URL will be returned by request.getRequestURL(), and information about the included page will ... Read More »