tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From André Warnier ...@ice-sa.com>
Subject Re: HelloWorld servlet, or just about
Date Fri, 19 Dec 2008 22:21:04 GMT
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:aw@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 ? "&lt;null&gt;"
: 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-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message