Category Archives: JSP

Setting Cookies

Introduction

An HTTP cookie (also called web cookie, Internet cookie, browser cookie, or simply cookie) is a small piece of data sent from a website and stored on the user’s computer by the user’s web browser while the user is browsing. Cookies were designed to be a reliable mechanism for websites to remember stateful information (such as items added in the shopping cart in an online store) or to record the user’s browsing activity (including clicking particular buttons, logging in, or recording which pages were visited in the past). They can also be used to remember arbitrary pieces of information that the user previously entered into form fields such as names, addresses, passwords, and credit card numbers. To set a cookie in a JSP, the following code is used:

Set-Cookie: cookie-value; expires=date; path=path; domain=domain-name; secure

 

Including a jsp fragment in a jsp



Introduction

This is useful if you need to include a header or footer and you already have them as separate jsp files.

<%@ include file="relativeFragment.jsp" %>

 

The if statement in a JSP WITH JSTL



Introduction

The JavaServer Pages Standard Tag Library (JSTL) allows you to use functional tags which simplify  programming in JSP’s. This example shows how it’s done with a simple test for a condition

<%-- Declare the core library --%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>

<%-- Simple  conditions --%>
<c: test='${param.p == "someValue"}'>
    Generate this template text  p equals someValue
</c:>

<c: test='${param.p}'>
    Generate this template text  p equals "true"
</c:>

Reference: