Servlet com jsp e classes java

Descrição

JSP Notas sobre Servlet com jsp e classes java, criado por Gabriel Rocha em 14-09-2017.
Gabriel Rocha
Notas por Gabriel Rocha, atualizado more than 1 year ago
Gabriel Rocha
Criado por Gabriel Rocha aproximadamente 7 anos atrás
3
0

Resumo de Recurso

Página 1

  index.html (dentro do pacote webinf)   <!DOCTYPE html> <!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. --> <html>     <head>         <title>TODO supply a title</title>         <meta charset="UTF-8">         <meta name="viewport" content="width=device-width, initial-scale=1.0">     </head>     <body>          <div><h1>Aluno</h1></div>         <form name="java" method="post" action="Controlar">         <h2>ID         <input type="text" name="id"><br>             RA         <input type="text" name="ra"><br>             Nome       <input type="text" name="nome"><br>             Curso      <input type="text" name="curso"><br>             Disciplina <input type="text" name="disciplina"><br>             Semestre   <input type="text" name="semestre"></h2>             <input type="submit" name="btnenviar" value="Concluir">                                                </form>              </body> </html>   Aluno.java (dentro do pacote bean) package bean; import java.io.Serializable; /**  *  * @author internet  */ public class Aluno  implements Serializable{     private int ID;     private String ra;     private String nome;     private String curso;     private String disciplina;     private String semestre;     public int getID() {         return ID;     }     public void setID(int ID) {         this.ID = ID;     }     public String getRa() {         return ra;     }     public void setRa(String ra) {         this.ra = ra;     }     public String getNome() {         return nome;     }     public void setNome(String nome) {         this.nome = nome;     }     public String getCurso() {         return curso;     }     public void setCurso(String curso) {         this.curso = curso;     }     public String getDisciplina() {         return disciplina;     }     public void setDisciplina(String disciplina) {         this.disciplina = disciplina;     }     public String getSemestre() {         return semestre;     }     public void setSemestre(String semestre) {         this.semestre = semestre;     }           }Controlar.java (dentro do pacote controler)   package controler; import bean.Aluno; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /**  *  * @author internet  */ public class Controlar extends HttpServlet {     /**      * Processes requests for both HTTP <code>GET</code> and <code>POST</code>      * methods.      *      * @param request servlet request      * @param response servlet response      * @throws ServletException if a servlet-specific error occurs      * @throws IOException if an I/O error occurs      */     protected void processRequest(HttpServletRequest request, HttpServletResponse response)             throws ServletException, IOException {         response.setContentType("text/html;charset=UTF-8");         try (PrintWriter out = response.getWriter()) {                          //out.print("Entrou");             int id = Integer.parseInt(request.getParameter("id"));             String ra = request.getParameter("ra");             String nome = request.getParameter("nome");             String curso = request.getParameter("curso");             String disc = request.getParameter("disciplina");             String semestre = request.getParameter("semestre");             //atribuir os valores ao objeto aluno.//             Aluno a = new Aluno();             a.setID(id);             a.setRa(ra);             a.setNome(nome);             a.setCurso(curso);             a.setDisciplina(disc);             a.setSemestre(semestre);             request.setAttribute("aluno", a);                          //enviar para a view//             request.getRequestDispatcher("saida.jsp").forward(request, response);         }     }     // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">     /**      * Handles the HTTP <code>GET</code> method.      *      * @param request servlet request      * @param response servlet response      * @throws ServletException if a servlet-specific error occurs      * @throws IOException if an I/O error occurs      */     @Override     protected void doGet(HttpServletRequest request, HttpServletResponse response)             throws ServletException, IOException {         processRequest(request, response);     }     /**      * Handles the HTTP <code>POST</code> method.      *      * @param request servlet request      * @param response servlet response      * @throws ServletException if a servlet-specific error occurs      * @throws IOException if an I/O error occurs      */     @Override     protected void doPost(HttpServletRequest request, HttpServletResponse response)             throws ServletException, IOException {         processRequest(request, response);     }     /**      * Returns a short description of the servlet.      *      * @return a String containing servlet description      */     @Override     public String getServletInfo() {         return "Short description";     }// </editor-fold> }saida.jsp (dentro do pacote webinf)     <%@page import="bean.Aluno"%> <%     Aluno a = (Aluno) request.getAttribute("aluno");     out.print(a.getID() + "<br>");     out.print(a.getRa() + "<br>");     out.print(a.getNome() + "<br>");     out.print(a.getCurso() + "<br>");     out.print(a.getDisciplina() + "<br>");     out.print(a.getSemestre() + "<br>"); %>  

Semelhante

Programação
Prepara Palhoça
Tabuada controlada em JSP
Gabriel Rocha
Sequência  fibonacci
Gabriel Rocha
ORIGAMID - Web Design
Guilherme Giorgi
Maior valor
Gabriel Rocha
Desenv. Paginas Padrão Web
silviacunha.m
Curso AlgaWorks - Angular, Rest,SpringBoot
Carlos Eduardo De Barros Souza
Oracle Certified Java Associate 7
Rafael Mulock
O.Objetos Java
Lorran Alves