Advertisement
Guest User

Untitled

a guest
Apr 20th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. final FormPanel formPanel = new FormPanel();
  2. formPanel.setEncoding(FormPanel.ENCODING_URLENCODED);
  3. formPanel.setMethod(FormPanel.METHOD_POST);
  4.  
  5. VerticalPanel verticalPanel = new VerticalPanel();
  6. verticalPanel.add(new Label("Username"));
  7. TextBox userid = new TextBox();
  8. userid.setName("username");
  9. verticalPanel.add(userid);
  10.  
  11. verticalPanel.add(new Label("Password"));
  12. PasswordTextBox passwd = new PasswordTextBox();
  13. passwd.setName("password");
  14. verticalPanel.add(passwd);
  15.  
  16. verticalPanel.add(new Button("Submit", new ClickHandler() {
  17.  
  18. @Override
  19. public void onClick(ClickEvent event) {
  20. formPanel.submit();
  21. }
  22. }));
  23.  
  24. formPanel.add(verticalPanel);
  25.  
  26. formPanel.setAction("/login");
  27.  
  28. formPanel.addSubmitHandler(new FormPanel.SubmitHandler() {
  29. public void onSubmit(SubmitEvent event) {
  30. }
  31. });
  32. formPanel.addSubmitCompleteHandler(new FormPanel.SubmitCompleteHandler() {
  33. public void onSubmitComplete(SubmitCompleteEvent event) {
  34. GWT.log(event.getResults());
  35. }
  36. });
  37.  
  38. RootPanel.get().add(formPanel);
  39.  
  40. @Override
  41. protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  42. String username = req.getParameter("username");
  43. String password = req.getParameter("password");
  44. resp.setContentType("text/plain");
  45.  
  46. System.out.println("Login request for " + username + " / " + password);
  47. if (username.equals("test1234")) {
  48. // send test response to output
  49. printMessageToOutputStream(resp, "OK", true, true);
  50. }
  51. else {
  52. printMessageToOutputStream(resp, "NOK", false , true);
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement