Thursday, November 24, 2005

Difference between Request Parameters and Scoped variables in Servlet and JSP.

Request parameters come from the browser (the HTML).
They can be sent to the server as QueryString parameters:

Code:
"http://myApp?first_name=Geetu"

or as Form Parameters:

Code:
form method="post" action="myApp"
input type="text" name="first_name" value="Geetu" /
input type="submit" value="Enter" /
/form

You would retrieve these in your servlet with: request.getParameter("first_name")

In a JSP, with EL you retrieve it with the param keyword:
${param.first_name}

They can not be objects because browsers can't send objects. They are always Strings or arrays of Strings.

Scoped variables, on the other hand are objects which are bound to page, request, session, or application scope. These variables can be accessed directly from EL

Objects are bound into the scopes using the setAttribute method in one of those scopes in Servlet, or using c:set tag in JSTL, or even using jsp:setProperty tag in JSP Standard Action Tag which will create and bind a variable into a scope if it does not already exist.

Wednesday, November 23, 2005

Where to find your Servlet code generated from your JSP Page

TOMCAT_HOME/work "folder"

Sunday, November 20, 2005

Tutorial on Dynamic Attributes

Dynamic Attributes

Thursday, November 17, 2005

All About Caching

Caching Tutorial

Solving the logout problem properly and elegantly

Logout Problem

Tutorials/Sample code of MVC architecture

MVC architecture

Wednesday, November 16, 2005

Fundamentals

Apache, Jakarta, Tomcat, Catalina, Coyote, Jasper

Apache is "The Apache Software Foundation" - an umberella organization that looks after a number of Open Source projects.

Jakarta is the group name for the Java based projects of the Apache Software Foundation.

Tomcat is a Web Server that handles server side Java(in the form of Servlets and JSP's), and it's a part of the Apache Jakarta project group. Tomcat is the "reference" implementation of the Servlet specification and jasper part of Tomcat is the "reference" implementation of the JSP specification.

Catalina is the Java Engine(JRE/JVM) that's built into Tomcat and provides environment in which Servlets can be run.

Coyote is the HTTP connector that's built into Tomcat and provides Tomcat with an interface that browsers can connect to.

Jasper is the Java Server Pages handler in Tomcat; internally, it deals with any compiling that's necessary, and converts JSP's into Servlets for Catalina to handle.

In computing, a reference implementation(or, infrequently, sample implementation) is a software example of a standard for use in helping others to implement their own versions of the standard. A standard is much easier to understand with a working example in hand.

"A reference implementation is, in general, an implementation of a specification to be used as a definitive interpretation for that specification. During the development of the conformance test suite, at least one relatively trusted implementation of each interface is necessary to (1) discover errors or ambiguities in the specification, and (2) validate the correct functioning of the test suite."

"Reference Implementation"

Developed concurrently with spec and test suite.
Verifies that specification is implementable.
Enables the test suite to be tested.
Serves as Gold Standard against which other implementations can be measured
Helps to clarify intent of specification where conformance tests are inadequate.

What is Apache ant?

An Ant is a Java-based built tool. In theory, it is kind of like Make, without Make's wrinkles and with the full portability of pure Java code.

Apache and Tomcat are different.

Apache is HTTP Web Server
Tomcat is a Web Container.

Web Applications usually use Apache and Tomcat configured together- with Apache as the HTTP Web Server and Tomcat as the Web Container.

The CLASSPATH is an environment variable that tells the command processor where to look for executable files e.g *.exe, *.com, *.bat files, including of course javac.exe and java.exe. The Classpath is one of the most confusing things in Java. Unfortunately, you must master it to even compile HelloWorld.

Tuesday, November 15, 2005

JSTL Tag Notes.

Topics Covered
• Overview
• The c:import Action
• The c:redirect Action
• The c:url Action
• The c:param Action
• Accessing External Resources
• Accessing Resources in Foreign Contexts
• Redirecting a Response

JSTL Tags

Monday, November 14, 2005

What happens when I don’t enter any values for login credentials(username/password) and submit the form blankly.

When u don't enter any value in the TextBox and make a submit, what u get in the server is just an empty string not a null. Try with this code

String inputRequest = request.getParameter("name");
if (inputRequest.equals("")){
System.out.println(“Enter some value”);
}

It will work fine.

It can also be tried with JSTL Tags

c:if test="${param.name eq null}"
jsp:forward page="errorPage.jsp" /
/c:if

This will not forward your request to errorPage.jsp. You got to use

c:if test="${empty param.name}"
jsp:forward page="errorPage.jsp" /
/c:if

Why can’t we access Servlet initParameter in EL like we do in Scriptlets?
<% request.getInitParameter(“name”); %>

Why this is giving error?
${pageContext.request.initparameter.name}
When we can access context initParameter like
${initParam.name} why can’t we do the same with Servlet initParameter.


You can not get Servlet int Parameters using this technique. The getInitParameter (param) does not fit in this case, because it require some arguments.

According to the Javabean spec. the property have getter setter methods in the form

public type1 getXXX() -- WITH NO ARGUMENTS.
public void setXXX(type1)

that’s it.

Now Consider the pageContext as bean Object. The PageContext class have methods like getServletContext(), getRequest(), getSession() etc. You can access these like pageContext.request, pageContext.servletContext etc in EL.

These SevletContext object have some methods like getMajorVersion(), getMinorversion() with no args. so we can access these methods treating it as properties to sevletContext bean as pageContext.servletContext.majorVersion and pageContext.servletContext.minorVersion.

My suggestion, if you want access to the initParams for the controller servlet, is to create a Map of the init params for the servlet and place it on the request as a scoped variable -- let's say named initParameters. You would then be able to obtain any param by name with ${requestScope.initParameters.name}.

Friday, November 11, 2005

URL Rewriting in JSP

URL Rewriting in JSP

PowerPoint Collections

Thursday, November 10, 2005

Is it necessary to include the default standard tld files in WEB-INF folder for JSTL Tags to work properly.


Few standard tld files

c.tld
c-1_0.tld
x.tld
fmt.tld
sql.tld

The necessary tld files are already contained within standard.jar. There is no need to extract them and place them anywhere else. In fact, doing so is a poor idea as it makes it possible for the tld’s and the jars to be out of sync with each other.

Hence jstl.jar and standard.jar files are sufficient which has to be included in WEB-INF/lib folder.

Wednesday, November 09, 2005

Attributes and their Accessibility in JSP Page


Attributes in "page scope" are the shortest and the most local. It is bound to the pageContext object for the current request. If an object is set as an attribute with in page scope then this object will not be available if the request is forwarded to another web component. Page Attributes are accessible/available only within the specific JSP page and is destroyed when the page has finished generating its output for the request.

Page scope is usually used with custom tags, and it is a way to pass data from the jsp page to the custom tag.

Attributes in “request scope” are accessible/available to any jsp page or servlet that are part of the specific request chain. For instance, if I made a GET request to servlet1, which gets forwarded to servlet2, which gets forwarded to jsp3, etc... attributes put in request scope in servlet1 would be available in jsp3 as well.

Attributes in "session scope" allows objects to be stored and retrieved across multiple requests for this user's session. Session Attributes are accessible/available to any jsp page or servlet that are part of the user’s session.

Attributes in "application scope" or context scope are accessible/available to all requests for the current application.

Tuesday, November 08, 2005

Tag Library Tutorial

Tag Library Tutorial