I'm sorry, but that does not match the specs AT ALL.
I specifically asked that the response should be plain text, and just
the userid.
ttttt.
;-)
Thanks, Chuck.
Caldarale, Charles R wrote:
From: André Warnier [mailto:a...@ice-sa.com]
Subject: HelloWorld servlet, or just about
Better yet (but I don't want to abuse your patience), just paste the
code right here below :
package myPackage;
import java.io.IOException;
import java.io.PrintWriter;
import java.security.Principal;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public final class ShowUser extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
Principal user = request.getUserPrincipal();
String userName = user == null ? "" : user.getName();
PrintWriter writer;
response.setContentType("text/html");
writer = response.getWriter();
writer.println("<html>");
writer.println("<head>");
writer.println("<title>Sample Servlet to display current
Principal</title>");
writer.println("</head>");
writer.println("<body>");
writer.println("<p>");
writer.println("Current user is " + (userName.length() == 0 ?
"<null>" : userName));
writer.println("</p>");
writer.println("</body>");
writer.println("</html>");
}
}
In your web.xml, include the following:
<servlet>
<servlet-name>UserServlet</servlet-name>
<servlet-class>myPackage.ShowUser</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>UserServlet</servlet-name>
<url-pattern>/showuser</url-pattern>
</servlet-mapping>
- Chuck
THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you received
this in error, please contact the sender and delete the e-mail and its
attachments from all computers.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org