Question: Exam 1 Enter your name
<-- index.html -->
@WebServlet(name = "exam1servlet", urlPatterns = {"/exam1servlet"})
public class exam1servlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("Exam1PU");
EntityManager em = emf.createEntityManager();
String key_name = request.getParameter("name");
Student student = em.find(Student.class, key_name);
request.setAttribute("score", Double.toString(student.getScore()) );
getServletContext().getRequestDispatcher("/exam1score.jsp")
.forward(request,response);
}
}
@Entity
public class Student implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private String name;
private double score;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getScore() {
return score;
}
public void setScore(double score) {
this.score = score;
}
}
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<-- exam1score.jsp -->
Name <%= request.getParameter("name") %>
Score <%= request.getAttribute("score") %>
We want to change the application so that an integer value (student number) rather than student name is entered in index.html. The database table will now have columns for student id (the new primary key), name (remains a column but not primary key), and score. The output jsp will now report student id, name and score.If the student id is not found in the database, the output jsp should report the message (Student ID not found).
Describe the changes needed to:
Index.html
Exam1score.jsp
Student.java
Exam1servlet.java
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
