Advertisement
xlrnxnlx

servlet-intToBin

Oct 16th, 2014
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.96 KB | None | 0 0
  1.     import java.io.IOException;
  2.     import java.io.PrintWriter;
  3.     import javax.servlet.ServletException;
  4.     import javax.servlet.annotation.WebServlet;
  5.     import javax.servlet.http.*;
  6.      
  7.     @WebServlet(urlPatterns = {"/ResultadoServlet"})
  8.     public class Binario extends HttpServlet {
  9.          @Override
  10.          protected void doPost(HttpServletRequest request, HttpServletResponse response)
  11.          throws ServletException, IOException {
  12.                response.setContentType("text/html;charset=UTF-8");
  13.          
  14.                String str = request.getParameter("N1");
  15.                if(str != null && !str.isEmpty()){
  16.                    int number = Integer.parseInt(str);
  17.                    String bin = Integer.toBinaryString(number);
  18.                    try(PrintWriter out = response.getWriter()){
  19.                        out.println( "<p>" + number + " em binário: " + bin +" </p>" );
  20.                    }
  21.                }
  22.          }
  23.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement