Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2011
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.90 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5.  
  6. package br.com.webapplication.controller;
  7.  
  8. import br.com.webapplication.model.Aluno;
  9. import java.io.IOException;
  10. import java.io.PrintWriter;
  11. import javax.servlet.ServletException;
  12. import javax.servlet.http.HttpServlet;
  13. import javax.servlet.http.HttpServletRequest;
  14. import javax.servlet.http.HttpServletResponse;
  15.  
  16. /**
  17.  *
  18.  * @author meathook
  19.  */
  20. public class CadastrarAluno extends HttpServlet {
  21.    
  22.     /**
  23.      * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
  24.      * @param request servlet request
  25.      * @param response servlet response
  26.      * @throws ServletException if a servlet-specific error occurs
  27.      * @throws IOException if an I/O error occurs
  28.      */
  29.     protected void processRequest(HttpServletRequest request, HttpServletResponse response)
  30.     throws ServletException, IOException {
  31.  
  32.         int idAluno = Integer.parseInt(request.getParameter("idAluno"));
  33.         int idadeAluno = Integer.parseInt(request.getParameter("idadeAluno"));
  34.         String nomeAluno = request.getParameter("nomeAluno");
  35.         String enderecoAluno = request.getParameter("enderecoAluno");
  36.         Aluno aluno = new Aluno();
  37.  
  38.         aluno.setIdAluno(idAluno);
  39.         aluno.setIdadeAluno(idadeAluno);
  40.         aluno.setNomeAluno(nomeAluno);
  41.         aluno.setEnderecoAluno(enderecoAluno);
  42.  
  43.         if(idadeAluno > 18)
  44.         {
  45.             System.out.println("Maior");
  46.         }
  47.         else
  48.         {
  49.             System.out.println("Menor");
  50.         }
  51.        
  52.  
  53.        
  54.  
  55.  
  56.     }
  57.  
  58.     // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
  59.     /**
  60.      * Handles the HTTP <code>GET</code> method.
  61.      * @param request servlet request
  62.      * @param response servlet response
  63.      * @throws ServletException if a servlet-specific error occurs
  64.      * @throws IOException if an I/O error occurs
  65.      */
  66.     @Override
  67.     protected void doGet(HttpServletRequest request, HttpServletResponse response)
  68.     throws ServletException, IOException {
  69.         processRequest(request, response);
  70.     }
  71.  
  72.     /**
  73.      * Handles the HTTP <code>POST</code> method.
  74.      * @param request servlet request
  75.      * @param response servlet response
  76.      * @throws ServletException if a servlet-specific error occurs
  77.      * @throws IOException if an I/O error occurs
  78.      */
  79.     @Override
  80.     protected void doPost(HttpServletRequest request, HttpServletResponse response)
  81.     throws ServletException, IOException {
  82.         processRequest(request, response);
  83.     }
  84.  
  85.     /**
  86.      * Returns a short description of the servlet.
  87.      * @return a String containing servlet description
  88.      */
  89.     @Override
  90.     public String getServletInfo() {
  91.         return "Short description";
  92.     }// </editor-fold>
  93.  
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement