Posted on April 29, 2009 by javaprograming
Use request.getRequestURI() or req.getServletPath(). The former returns the path to the script including any extra path information following the name of the servlet; the latter strips the extra path info. The following example demonstrates it: URL http://www.host.com/servlets/HelloEcho/extra/info?height=100&width=200 getRequestURI /servlets/HelloEcho/extra/info getServletPath /servlets/HelloEcho getPathInfo /extra/info getQueryString height=100&width=200 This is useful if your [...]
Filed under: 1 | Leave a Comment »
Posted on April 29, 2009 by javaprograming
As the name says it, it is communication between servlets. Servlets talking to each other. There are many ways to communicate between servlets, including : * Request Dispatching * HTTP Redirect * Servlet Chaining * HTTP request (using sockets or the URLConnection class) * Shared session, request, or application [...]
Filed under: Servlets | Leave a Comment »
Posted on April 29, 2009 by javaprograming
WAR (or “web archive”) file is simply a packaged webapp directory. It is created using the standard Java jar tool. For example: jar cf ../mywebapp.war * How can I call a servlet from a JSP page? How can I pass variables from the JSP that the servlet can access? You can use <jsp:forward [...]
Filed under: Servlets | Leave a Comment »
Posted on April 29, 2009 by javaprograming
A web application is a collection of servlets, html pages, classes, and other resources that can be bundled and run on multiple containers from multiple vendors. A web application is rooted at a specific path within a web server. The contents of the WEB-INF directory are: /WEB-INF/web.xml deployment descriptor /WEB-INF/classes/* directory for servlet and [...]
Filed under: Servlets | Leave a Comment »
Posted on April 29, 2009 by javaprograming
A servlet bean is a serializable servlet that follows the JavaBeans component architecture, basically offering getter/setter methods.
Filed under: Servlets | Leave a Comment »
Posted on April 29, 2009 by javaprograming
Instead of using getParameter() with the ServletRequest, as you would with single-valued parameters, use the getParameterValues() method. This returns a String array (or null) containing all the values of the parameter requested.
Filed under: Servlets | Leave a Comment »
Posted on April 29, 2009 by javaprograming
GenericServlet is for servlets that might not use HTTP, like for instance FTP servlets. Of course, it turns out that there’s no such thing as FTP servlets, but they were trying to plan for future growth when they designed the spec. Maybe some day there will be another subclass, but for now always use HttpServlet. [...]
Filed under: Servlets | Leave a Comment »
Posted on April 29, 2009 by javaprograming
A “servlet engine” is a program that plugs in to a web server and runs servlets. The term is obsolete; the preferred term now is “servlet container” since that applies both to plug-in engines and to stand-alone web servers that support the Servlet API.
Filed under: Servlets | Leave a Comment »
Posted on April 29, 2009 by javaprograming
One way to do this is by using a URLConnection to open a stream to your desired URL, then copy the data out of the stream to a file on your local file system.
Filed under: Servlets | Leave a Comment »
Posted on April 29, 2009 by javaprograming
Yes, you can invoke the JSP error page and pass the exception object to it from within a servlet. The trick is to create a request dispatcher for the JSP error page, and pass the exception object as a javax.servlet.jsp.jspException request attribute. How can I download a file (for instance, a Microsoft Word document) [...]
Filed under: Servlets | Leave a Comment »