if (searchSpec.getName().equals(searchEngine)) { String url =
searchSpec.makeURL(searchString, numResults); response.sendRedirect(url); return; } }
reportProblem(response, \ }
private void reportProblem(HttpServletResponse response, String message)
throws IOException {
response.sendError(response.SC_NOT_FOUND, \ }
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { doGet(request, response); } }
19. JSP源代码实例二
转:jsp源码实例(获取jsp各种参数) Marty Hall [2001-01-06]
作者:Marty Hall package coreservlets; import java.io.*;
import javax.servlet.*; import javax.servlet.http.*; import java.util.*;
/** Creates a table showing the current value of each * of the standard CGI variables. *
* Taken from Core Servlets and JavaServer Pages * from Prentice Hall and Sun Microsystems Press, * http://www.coreservlets.com/.
* © 2000 Marty Hall; may be freely used or adapted. */
public class ShowCGIVariables extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { response.setContentType(\ PrintWriter out = response.getWriter();
String[][] variables =
{ { \ { \
String.valueOf(request.getContentLength()) },
{ \ { \
getServletContext().getRealPath(\ { \
{ \ { \ { \ { \ { \ { \ { \ { \ { \
String.valueOf(request.getServerPort()) },
{ \ { \
getServletContext().getServerInfo() } };
String title = \ out.println(ServletUtilities.headWithTitle(title) + \
\ \ \ \ for(int i=0; ivarValue = \
out.println(\ }
out.println(\ }
/** POST and GET requests handled identically. */ public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { doGet(request, response); }
}
20. JSP源代码实例三
转:jsp源码实例(获取表单参数) Marty Hall [2001-01-06]
作者:Marty Hall package coreservlets; import java.io.*;
import javax.servlet.*; import javax.servlet.http.*; import java.util.*;
/** Shows all the parameters sent to the servlet via either * GET or POST. Specially marks parameters that have * no values or multiple values. *
* Taken from Core Servlets and JavaServer Pages * from Prentice Hall and Sun Microsystems Press, * http://www.coreservlets.com/.
* © 2000 Marty Hall; may be freely used or adapted. */
public class ShowParameters extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { response.setContentType(\ PrintWriter out = response.getWriter();
String title = \ out.println(ServletUtilities.headWithTitle(title) + \
\ \ \
\
Enumeration paramNames = request.getParameterNames(); while(paramNames.hasMoreElements()) {
String paramName = (String)paramNames.nextElement(); out.print(\ String[] paramValues =
request.getParameterValues(paramName); if (paramValues.length == 1) {
String paramValue = paramValues[0]; if (paramValue.length() == 0) out.println(\ else
out.println(paramValue); } else {
out.println(\
for(int i=0; iout.println(\ } }
out.println(\ }
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { doGet(request, response); } }