How do I create a hyperlink in java?

Posted by Justin984 on Stack Overflow See other posts from Stack Overflow or by Justin984
Published on 2012-08-30T03:36:13Z Indexed on 2012/08/30 3:38 UTC
Read the original article Hit count: 239

Filed under:
|
|

I'm going through the google app engine tutorials at https://developers.google.com/appengine/docs/java/gettingstarted/usingusers

I'm very new to google app engine, java and web programming in general. So my question is, at the bottom of the page it says to add a link to allow the user to log out. So far I've got this:

public void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws IOException {
    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();

    if(user != null){
        resp.setContentType("text/plain");
        resp.getWriter().println("Hello, " + user.getNickname());

        String logoutLink = String.format("<a href=\"%s\">Click here to log out.</a>",
            userService.createLogoutURL(req.getRequestURI()));
        resp.getWriter().println(logoutLink);
    }else {
        resp.sendRedirect(userService.createLoginURL(req.getRequestURI()));
    }
}

However instead of a link, the full string is printed to the screen including the tags. When I look at the page source, I have no tags or any of the other stuff that goes with a webpage. I guess that makes sense considering I've done nothing to output any of that. Do I just do a bunch of resp.GetWriter().println() statements to output the rest of the webpage, or is there something else I don't know about?

Thanks!

© Stack Overflow or respective owner

Related posts about java

Related posts about google-app-engine