im trying to fix the part of my program that allows the user to edit some classes. but i keep getting this error error java.lang.NumberFormatException: For input string: "entry.id" for this part of my code Integer id = Integer.valueOf( request.getParameter( "id" ) ) and i have no idea how to fix it. i get that error in my controller class at the bottom
heres my jsp that does the display
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <jsp:useBean id="gb" class="cs320Homework1.servlet.CourseDisplay" scope="application" /> <!-- param takes the value of what is typed in the edit --> <c:if test="${not empty param.edit}"> <c:set target="${entry.id}" property="name" value="${param.code}" /> <c:set target="${entry.id}" property="message" value="${param.title}" /> <c:choose> </c:choose> <c:redirect url="CourseDisplay.jsp" /> </c:if> <!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=ISO-8859-1"> <title>Edit Course</title> </head> <body> <c:choose> <c:when test="${not empty user}"> <form action="EditCourse" method="post"> Code: <input type="text" name="code" value="${entry.code}" /><br /> Message: <input type="text" name="code" value="${entry.message}" /><br /> <input type="submit" name="edit" value="Edit" /> <input type='hidden' name='id' value="${param.id}" /> </form> <a href='Logout'>Logout</a> </c:when> <c:otherwise> <c:redirect url="Login"></c:redirect> </c:otherwise> </c:choose> </body> </html>
and here my controller
package cs320Homework1.servlet; import java.io.IOException; import java.io.PrintWriter; import java.util.List; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import cs320Homework1.servlet.CourseEntry; @WebServlet("/EditCourse") public class EditCourse extends HttpServlet { private static final long serialVersionUID = 1L; public EditCourse() { super(); } @SuppressWarnings({ "unchecked", "unused" }) private CourseEntry getEntry( Integer id ) { List<CourseEntry> entries = (List<CourseEntry>) getServletContext().getAttribute( "entries" ); for( CourseEntry entry : entries ) if( entry.getId()==id ) return entry; return null; } @SuppressWarnings("unchecked") protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Integer id = Integer.valueOf( request.getParameter( "id" ) ); CourseEntry entry = getEntry( id ); request.setAttribute( "entry", entry ); request.getRequestDispatcher( "/WEB-INF/EditCourse.jsp" ).forward( request, response ); } @SuppressWarnings("unchecked") protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String code = request.getParameter("code"); String title = request.getParameter("title"); String[] prerequisites = request.getParameterValues("prerequisites"); Integer index = Integer.valueOf(request.getParameter("id")); List<CourseEntry> entries = (List<CourseEntry>) getServletContext() .getAttribute("entries"); if (prerequisites == null) { entries.get(index).setPrerequisites(new String[] {}); } else { entries.get(index).setPrerequisites(prerequisites); } entries.get(index).setCode(code); entries.get(index).setTitle(title); response.sendRedirect("CourseDisplay"); } }