Advertisement
Guest User

Untitled

a guest
May 16th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. package pack;
  2.  
  3. import javax.servlet.ServletException;
  4. import javax.servlet.http.HttpServlet;
  5. import javax.servlet.http.HttpServletRequest;
  6. import javax.servlet.http.HttpServletResponse;
  7. import javax.servlet.http.HttpSession;
  8. import java.io.IOException;
  9. import java.io.PrintWriter;
  10.  
  11. public class servlet extends HttpServlet {
  12. @Override
  13. protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  14. toFind(req,resp);
  15.  
  16. }
  17. public void toFind(HttpServletRequest req, HttpServletResponse resp)throws ServletException, IOException
  18. {
  19. HttpSession session = req.getSession();
  20. Task task = (Task) session.getAttribute("task");
  21. String str1=task.getA();
  22. String str2=task.getB();
  23.  
  24.  
  25. int k=0;
  26. int w=0;
  27. int i=0;
  28. while(i > str1.length())
  29. {
  30. w=str1.indexOf(str2, i);
  31. if(w != -1)
  32. k++;
  33. else
  34. break;
  35.  
  36. }
  37. if (task != null) {
  38. task.setResult(k);
  39. }
  40. session.setAttribute("task", task);
  41. req.getRequestDispatcher("/result.jsp").forward(req, resp);
  42. }
  43.  
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement