> From: André Warnier [mailto:[email protected]]
> Subject: Re: HelloWorld servlet, or just about
>
> I would basically need only a response with
>
> HTTP status line
> MyHeader: johnsmith
So take the code I posted, rip out all the HTML stuff, and just send the text
of the userid. Since it doesn't even have to be real HTTP, you don't even need
a header, just the userid as a string. You'll need some method of indicating
an empty string, unless you know the session has *always* been authenticated.
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/plain"); // probably not necessary
writer = response.getWriter();
writer.println(userName.length() == 0 ? "<null>" : userName));
}
}
- 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: [email protected]
For additional commands, e-mail: [email protected]