Mark Damon Hughes NetRexx Servlets [Parental Advisory: Explicit Lyrics] [about]

Index  |   What is NetRexx?  |   NetRexx Servlets  |  

One of NetRexx's greatest strengths is string manipulation, and of course the web is nothing but text.

Rather than accumulate HTML in the servlet, I prefer to set request scope attributes, then forward to a JSP template page which uses JSTL and EL (but no inline Java code!). This lets me keep all business logic in the servlet, and all display logic in the JSP template page.


/* Greeting.nrx */

package foo

import javax.servlet.
import javax.servlet.http.

class Greeting extends NrxServlet
    method doGet(request=HttpServletRequest, response=HttpServletResponse)
	name = param(request, "name")
	name = name.reverse()
	request.setAttribute("name", name.toString())
	forward(request, response, "/greeting.jsp")

<!-- greeting.jsp -->
<p>Hello, ${requestScope.name}!</p>

/* NrxServlet.nrx */

package foo

import javax.servlet.
import javax.servlet.http.

class NrxServlet extends HttpServlet
    method param(request=HttpServletRequest, key)
	value = request.getParameter(key)
	if value == null then signal ServletException("Missing parameter" key)
	return Rexx value

    method forward(request=HttpServletRequest, response=HttpServletResponse, path)
            signals ServletException, IOException
	rd = getServletContext().getRequestDispatcher(path)
	rd.forward(request, response)
* nrxservlet.zip
A zip file containing the servlet, web.xml, and the NetRexx runtime library (NetRexxR.jar). Drop it in your Tomcat webapps dir, or copy it to get a framework for building new NetRexx webapps.

Last modified: 2006Jan13
Created

Feedback  | Key: ] =local file, * =off-site link  | Copyright © 2003-2010 by Mark Damon Hughes | Subscribe with RSS 2.0