forward

Handling trailing slash characters with Nginx 301 redirects

As a quick Nginx configuration example, if you need to configure a 301 Redirect with Nginx, and you also need to account for trailing slash characters in the original URL, I can confirm that this solution works for me:

rewrite /foo/bar/baz/?$  /foo/bar/baz.html permanent;

This Nginx configuration line will forward both of these URIs to the new URI:

How to test for a valid user session in a JSP

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?"

How to forward from one JSP to another JSP

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/.

 

Servlet forward example - How to forward from a servlet to a JSP

Here's an example of how to forward from a servlet to a JSP in your J2EE code. I can never remember how to do a forward like this when I need it, so even though this example is pretty easy, I've put it out here so I can find it later.

The typical scenario is that you're working on a Java servlet, and you need to forward the user from that servlet to a JSP. Assuming the name of the JSP is "searchResults.jsp", here's the code that will forward from your servlet to that JSP: