package de.uhilger.wbx.web;
import java.io.IOException;
import java.io.OutputStream;
import java.security.Principal;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.catalina.servlets.DefaultServlet;
/**
*
*/
public class ViewServlet extends DefaultServlet {
private static final Logger logger = Logger.getLogger(ViewServlet.class.getName());
/**
* Handles the HTTP GET
method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
/*
ServletOutputStream out = response.getOutputStream();
out.print("
start: " + start + "
"); out.print("userName.length: " + userName.length() + "
"); out.print("contextPath.length(): " + contextPath.length() + "
"); out.print("requestUrlStr.length(): " + requestUrlStr.length() + "
"); start += contextPath.length(); start++; out.print("start: " + start + "
"); int end = start + userName.length(); try { result = requestUrlStr.substring(start, end); } catch(Exception ex) { result = ex.getMessage(); } } return result; } private String getHtml(String label, String theVal) { StringBuffer buf = new StringBuffer(); buf.append(""); buf.append(label); buf.append(": "); if(theVal == null) { buf.append("null"); } else { buf.append(theVal); } buf.append("
"); return buf.toString(); } private String getUserName(HttpServletRequest hr) { String userName = null; Object p = hr.getUserPrincipal(); if (p instanceof Principal) { userName = ((Principal) p).getName(); } return userName; } /** * Returns a short description of the servlet. * * @return a String containing servlet description */ @Override public String getServletInfo() { return "Short description"; }// }