HttpServletResponse.SC_BAD_REQUEST : HttpServletResponse « javax.servlet.http « Java by API






HttpServletResponse.SC_BAD_REQUEST

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class GoTo extends HttpServlet {

  public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException,
      IOException {
    // Determine the site where they want to go
    String site = req.getPathInfo();
    String query = req.getQueryString();

    // Handle a bad request
    if (site == null) {
      res.sendError(res.SC_BAD_REQUEST, "Extra path info required");
    }

    // Cut off the leading "/" and append the query string
    // We're assuming the path info URL is always absolute
    String url = site.substring(1) + (query == null ? "" : "?" + query);

    // Log the requested URL and redirect
    log(url); // or write to a special file
    res.sendRedirect(url);
  }
}

           
       








Related examples in the same category

1.HttpServletResponse: addCookie(Cookie arg0)
2.HttpServletResponse.SC_MOVED_TEMPORARILY
3.HttpServletResponse: encodeURL(String url)
4.HttpServletResponse: sendRedirect(String arg0)
5.HttpServletResponse: setContentType( text/html; charset=UTF-8 );
6.HttpServletResponse: setHeader(String name, String value)
7.ServletResponse: setBufferSize(int arg0)
8.HttpServletResponse: setContentType("text/vnd.wap.wml")
9.HttpServletResponse: sendError(int arg0, String arg1)
10.HttpServletResponse: setHeader(String name, String value) (2)
11.HttpServletResponse: setStatus(int status)