OK this is wierd. When I change my login to FORM authentication instead of BASIC The
page doesn't display the username with the code below but if I don't cloas ethe
browser and I go back and access my servlet again it shows my username.
|
| import javax.servlet.http.HttpServlet;
| import javax.servlet.http.HttpServletRequest;
| import javax.servlet.http.HttpServletResponse;
| // Support classes
| import java.io.IOException;
| import java.io.PrintWriter;
| import java.security.Principal;
|
| public class MessageServlet extends HttpServlet {
|
| ...
|
| // Handle the GET HTTP Method
| public void doGet(HttpServletRequest request,
| HttpServletResponse response)
| throws IOException {
| String username = "";
|
| String message;
| message = processRequest(request);
| generateResponse(message, username, response);
| }
|
| // Handle the POST HTTP Method
| public void doPost(HttpServletRequest request,
| HttpServletResponse response)
| throws IOException {
| // String username = request.getParameter("j_username");
|
| Principal user = request.getUserPrincipal();
| String username = user.getName();
|
| String message;
| message = processRequest(request);
| generateResponse(message, username, response);
| }
|
| // Process the request
| private String processRequest(HttpServletRequest request) {
|
| ...
|
| int msg_index = (int) (Math.random() * list.length);
|
| return list[msg_index];
| }
|
| // Generate the HTML response
| private void generateResponse(String message, String username,
| HttpServletResponse response)
| throws IOException {
|
| response.setContentType("text/html");
| PrintWriter out = response.getWriter();
|
| out.println("<HTML>");
| out.println("<HEAD>");
| out.println("<TITLE>Message Servlet</TITLE>");
| out.println("</HEAD>");
| out.println("<BODY BGCOLOR=\"white\">");
| out.println("Hi " + username);
| out.println("Your message is: <BR>");
| out.println("<BLOCKQUOTE><B>" + message + "<B></BLOCKQUOTE>");
| out.println("</BODY>");
| out.println("</HTML>");
|
| out.close();
| }
| }
<a
href="http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3825714#3825714">View
the original post</a>
<a
href="http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3825714>Reply
to the post</a>
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user