JSP (Java Server Page) - envio devarios datos a la vez

 
Vista:
sin imagen de perfil

envio devarios datos a la vez

Publicado por andres (2 intervenciones) el 14/03/2017 22:09:09
hola soy nuevo en el foro y tambien llevo poco tiempo aprendiendo a aprogramar. estoy haciendo una aplicacion de registro y consulta de notas, todo va bien excepto cuando llego al listado donde un profesor asigna la nota a varios estudiantes, la aplicacion envia solo el primer dato o la primera nota (asignada al primer estudiante). no se como hacer para que envie todas las calificaciones de todos los estudiantes registrados a su materia. he revizado algunas paginas y saco la conclusion que podria resolver si asigno un valor dinamico a la variable RNota, o a traves de un array pero he intentado y aun no encontro la forma de hacerlo. dejo el codigo. Muchas Gracias

lista estudiantes y campo de texto para que el docente digite la calificacion listEstNota.jsp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<%@page import="Controlador.Registros"%>
<%@page session="true" %>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="Controlador.Consulta"%>
<%@page import="Controlador.Conexion"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
 
<html>
 
 
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>..::Registro Notas::..</title>
        <style type="text/css">
            body{width: 750px;}
           h2{position: relative; top: 40px;left: 310px;}
           body{background-image: url('frenteProfesor.jpg');background-repeat: no-repeat;}
           form{position: relative; top: 10px;left: 340px; }
           a{position: absolute; top: 90px;left: 90px;}
           a.rr{position: absolute; top: 100px;left: 90px;}
           #cierro{ position: absolute; left: 530px; top: 5px; color:white;}
           p{position: relative; top: -65px;left: 30px;color: white}
        </style>
    </head>
    <body >
 
<%String variables = request.getParameter("mates");%>
 
<h2>Listado Estudiantes, materia:  <%=variables%> </h2>
 
<%
       String usuario = "";
       String mat = "";
       HttpSession sesionIntento = request.getSession();
 
       usuario = (String) sesionIntento.getAttribute("usuario");
 
 
       Conexion con = new Conexion ();
          Consulta sulta = new Consulta();
            PreparedStatement pst =  null;
            ResultSet   rs = null;
          try{
 
              con.getConexion();
              String Consultas = "select * from  idmateria_idestudiante_idprofesor_nota AC, estudiantes A, materias C where  AC.id_est = A.id_est and AC.id_materia=C.id_materia and materia ='"+variables+"'";
              pst  = con.getConexion().prepareCall(Consultas);
              rs = pst.executeQuery();
%>
<p>bienvenido, PROFESOR: <%=usuario%></p>
 
 
<form action="cargaNota" method="POST" >
  <table  border="1px">
      <thead>
    <tr>
     <td>ID</td>
     <td>Nombre</td>
     <td>Apellido</td>
     <td>Codigo</td>
      <td>Nota</td>
      <td>Nota  Registrada</td>
    </tr>
      </thead>
 
 
<%
 
 
              while (rs.next()){
              %><tbody><%
          %><tr><%
 
 
                 String materiasV0=rs.getString("id_tabla");
                 %><th><% out.print(materiasV0); %></th><%
 
                  String materiasV1=rs.getString("nombre");
                %><th><% out.print(materiasV1); %></th><%
                 String materiasV2=rs.getString("apellido");
                %><th><% out.print(materiasV2);%></th><%
                 String materiasV3=rs.getString("usuario");
                %><th><% out.print(materiasV3); %></th><%
 
                %><th><input type="text"  name="Rnota" /><br></th><%
 
 
 
 
       %><th><input type="hidden"  name="id"  value="<%=materiasV0%>"/><br></th><%
             %><%
 
 
 
        }
 
 
 
 
         }catch (Exception e){
              out.print("error"+e);
}
 
 
%>
 
 
 
     </tr>
          <tr>
            <th><input type="submit"  name="registrar"/></th>
          </tr>
              </tbody>
        </table>
</form>
 
 
 
     <a id="rr"href="logeadoProf.jsp">Carga de Notas</a><br><br><br><br><br>
       <a  href="ActProf.jsp">Actualizacion</a><br><br><br>
 
<div id="cierro">
 
   <a id="cierro" href="cerrarSesion.jsp">Cerrar</a>
 
</div>
 
    </body>
</html>
la informacion la envio a un servlet que se encarga de enviar los parametros al paquete controlador quien es el que hace la carga

SERVLET:CargaNOta.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
 
package Servlet;
 
import Controlador.Registros;
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 ancasu
 */
public class cargaNota 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");
       PrintWriter out = response.getWriter();
 
     int id_tabla = Integer.parseInt(request.getParameter("id"));
       System.out.print(id_tabla);
      String nota = request.getParameter("Rnota");
 
 
     Registros co = new Registros ();
 
       if (co.RegNota(id_tabla, nota)){
           response.sendRedirect("logeadoProf.jsp");
       }else {
           response.sendRedirect("listEstNota.jsp");
       }
 
 
    }
 
 
    // <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>
 
}

consulta ala base de datos

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
public boolean RegNota ( Integer id_tabla, String nota ){
 
 
        PreparedStatement ps = null;
 
      try{
 
 
 
         String Consulta = "update idmateria_idestudiante_idprofesor_nota set nota  = '"+nota+"' where id_tabla = "+id_tabla;
         ps = getConexion().prepareStatement(Consulta);
 
 
 
          if (ps.executeUpdate()==1){
              return true;
          }
 
      }catch(SQLException ex){
          System.err.print("ERROR"+ex);
      }finally{
          try {
              if(getConexion()!=null)getConexion().close();
              if (ps!=null)ps.close();
          }catch(SQLException e){
                  System.err.print(e);
                  }
 
 
 
      }
 
 
       return false;
    }
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder