Home > Articles

  • Print
  • + Share This

Enhancing the Monthly Calendar JSP

In this section, you will enhance the JSP you created in the previous chapter rather than reinvent one from the ground up. Most application development works that way. You always have to enhance or fix an application rather than build it again from scratch. An extra change you can make is to avoid highlighting the current day in the calendar.

Extracting User Parameters Using the Request Implicit Object

You can obtain the values specified by the user for an input field using another implicit object prepared by the JSP container, the request object, within a scriptlet as shown in the following example:

<% String valueAsString = request.getParameter("parameter"); %>

You could directly print it using an expression:

<%= request.getParameter("parameter") %>

In this case, you will need to create a scriptlet that will extract the parameters and parse them to obtain the numeric values for the month and year. After you extract these values you need to set them in the calendar instance to make it represent the specified date rather than the current one. Add a calendar initialization scriptlet in the body before the "Generate Cells for Month" scriptlet as shown in Listing 3.6. Figure 3.4 shows the output for April, 1980.

Figure 3.4 The Generated Calendar for the specified date

Listing 3.6 month.jsp: The Extract Parameters Scriptlet

<%
 int month = Integer.parseInt(request.getParameter("month"));
 int year = Integer.parseInt(request.getParameter("year"));
 cal.set(year, month, 1);
%>
  • + Share This
  • 🔖 Save To Your Account

Related Resources

There are currently no related titles. Please check back later.