|
12 | 12 | * See the License for the specific language governing permissions and |
13 | 13 | * limitations under the License. |
14 | 14 | */ |
| 15 | + |
15 | 16 | // [START users_API_example] |
16 | 17 | package com.example.appengine.users; |
17 | 18 |
|
| 19 | +import com.google.appengine.api.users.UserService; |
| 20 | +import com.google.appengine.api.users.UserServiceFactory; |
| 21 | + |
18 | 22 | import java.io.IOException; |
| 23 | + |
19 | 24 | import javax.servlet.http.HttpServlet; |
20 | 25 | import javax.servlet.http.HttpServletRequest; |
21 | 26 | import javax.servlet.http.HttpServletResponse; |
22 | | -import com.google.appengine.api.users.UserService; |
23 | | -import com.google.appengine.api.users.UserServiceFactory; |
24 | 27 |
|
25 | 28 | public class UsersServlet extends HttpServlet { |
26 | | - @Override |
27 | | - public void doGet(HttpServletRequest req, HttpServletResponse resp) |
28 | | - throws IOException { |
29 | | - UserService userService = UserServiceFactory.getUserService(); |
30 | | - |
31 | | - String thisURL = req.getRequestURI(); |
32 | | - |
33 | | - resp.setContentType("text/html"); |
34 | | - if (req.getUserPrincipal() != null) { |
35 | | - resp.getWriter().println("<p>Hello, " + |
36 | | - req.getUserPrincipal().getName() + |
37 | | - "! You can <a href=\"" + |
38 | | - userService.createLogoutURL(thisURL) + |
39 | | - "\">sign out</a>.</p>"); |
40 | | - } else { |
41 | | - resp.getWriter().println("<p>Please <a href=\"" + |
42 | | - userService.createLoginURL(thisURL) + |
43 | | - "\">sign in</a>.</p>"); |
44 | | - } |
| 29 | + @Override |
| 30 | + public void doGet(HttpServletRequest req, HttpServletResponse resp) |
| 31 | + throws IOException { |
| 32 | + UserService userService = UserServiceFactory.getUserService(); |
| 33 | + |
| 34 | + String thisUrl = req.getRequestURI(); |
| 35 | + |
| 36 | + resp.setContentType("text/html"); |
| 37 | + if (req.getUserPrincipal() != null) { |
| 38 | + resp.getWriter().println("<p>Hello, " |
| 39 | + + req.getUserPrincipal().getName() |
| 40 | + + "! You can <a href=\"" |
| 41 | + + userService.createLogoutURL(thisUrl) |
| 42 | + + "\">sign out</a>.</p>"); |
| 43 | + } else { |
| 44 | + resp.getWriter().println("<p>Please <a href=\"" |
| 45 | + + userService.createLoginURL(thisUrl) |
| 46 | + + "\">sign in</a>.</p>"); |
45 | 47 | } |
| 48 | + } |
46 | 49 | } |
47 | 50 | // [END users_API_example] |
48 | 51 |
|
0 commit comments