jsp

How to forward from a Java servlet to a JSP alvin November 11, 2009 - 9:05am

Here's a quick example that shows a complete method that I use in a Java servlet to forward to a JSP (JavaServer Page).

Just pass the method an HttpServletRequest, an HttpServletResponse, and a URL, and you're in business. Note that my JSP url string typically looks something like "/myPage.jsp".

How to test for a valid user session in a JSP alvin June 1, 2009 - 8:54am

Note: This approach is very old; Java/JSP scriptlets were deprecated a long time ago. I don't have time to update this article to the correct, modern approach, but I hope this JSP session example will point you in the right direction.

Every once in a while I'm asked something like, "How can I tell if I have a valid user session in my JSP code?"

JSP URI/URL - How to get the request URI, URL, and Context from a JSP

JSP URI/URL FAQ: How do I get a URI or URL from a JSP (the request URI or request URL)?

I was just working with a JSP, and trying to remember how to get information that can be very helpful inside of a JSP, specifically how to determine the Context, URI, and URL from within a JSP.

To that end, here's the Java source code for a JSP I wrote that will display the Context, URI, and URL for this JSP when it is accessed from a browser:

How to create zebra stripes in JSP tables alvin May 12, 2009 - 7:35am

It's been a long time since I worked on an old-school JSP (without the benefit of a framework like JSF or Struts), but I've wanted to add alternating row stripes ("zebra stripes") to some HTML tables in some old JSP's for a long time. I like tables with zebra stripes because they're easier to read, so now that I have some free time, I finally got this done.

Now that I have all of my JSP/CSS code working properly, I thought I'd share it all here in the form of a "recipe".

Deploy only your JSP files with this Ant build task

A lot of times when you're working on a Java web application you only need to deploy your JSP files. This happens, for instance, when you're just editing the JSP files to modify the look and feel of your web application. In cases like this there's no need to rebuild your entire application, deploy it, then restart your application server (Tomcat, Glassfish, JBoss, whatever).

How to forward from one JSP to another JSP alvin May 30, 2008 - 7:03pm

When you need to forward from one JavaServer Page (JSP) to another JSP, here's all you have to do:

<jsp:forward page="/faces/success.jsp" />

In the example shown I happen to be working on a small JavaServer Faces (JSF) application, so the URL in this example includes the string /faces/.

 

Ant WAR task - A sample Ant build script that builds a WAR file

You'll probably have to know a little bit about Java, Ant, and build files for this sample build.xml file to be any use to you, but if you're looking for a sample Ant build script that can be used to create a war file, or one that simple uses a war task, this example might work for you.

I'm not going to provide any explanation of any of this right now, but if I have time in the future I'll come back here and add a few comments about how this build script works.

JSP CGI - A JSP that prints the equivalent of CGI variables alvin July 13, 2007 - 2:18pm

I created a JSP this morning that prints out the equivalent of most traditional CGI parameters. Sometimes I use these to debug a problem, other times I use them within JSP/servlet code for other non-debug purposes.

Here's the Java source code for my JSP CGI page, which I named cgiParams.jsp. As you can see, most of these variables come from the JSP request object:

Servlet redirect example - redirecting from a servlet to a JSP alvin July 31, 2005 - 12:05pm

Java servlet redirect FAQ: Can you provide an example of how to perform a Java servlet redirect?

Some time ago I wrote about forwarding from a servlet to a JSP. Depending on the circumstance I might rather redirect from a servlet to a JSP. When I need to to do a redirect instead of a forward I use this code: