我創建了數據庫,表名是1.employee(master),2.department。我使用SQL內部連接方法以連接格式顯示結果。然後我試圖更新員工表,我收到這樣的錯誤。爲什麼我得到這個錯誤?HTTP狀態500 - Servlet執行引發異常?
的錯誤是:
> HTTP Status 500 - Servlet execution threw an exception
>
> type Exception report
>
> message Servlet execution threw an exception
>
> description The server encountered an internal error that prevented it from fulfilling this request.
>
> exception
>
> javax.servlet.ServletException: Servlet execution threw an exception
>
> root cause
>
> java.lang.Error: Unresolved compilation problem:
> setDep_id cannot be resolved or is not a field
>
> com.controller.UserController.doPost(UserController.java:85)
> javax.servlet.http.HttpServlet.service(HttpServlet.java:643)
> javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
,並在錯誤被以下路線爲:
1.controller.java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
User user=new User();
user.setEmpName(request.getParameter("empName"));
user.setEmpAddress(request.getParameter("empAddress"));
user.setDep_id(request.getParameter("dep_id"));
String emp_id=request.getParameter("emp_id");
if(emp_id!=null && !emp_id.toString().equalsIgnoreCase(""))
{
user.setEmp_id(Integer.parseInt(emp_id));
dao.updateUser(user);
}
else
{
dao.addUser(user);
}
RequestDispatcher view=request.getRequestDispatcher(EMPLOYEE_LIST);
request.setAttribute("users", dao.getAllUsers());
view.forward(request, response);
}
2.User.java:
package;
class
public int dep_id;
public int getDep_id()
{
return dep_id;
}
public void setDep_id(int dep_id)
{
this.dep_id=dep_id;
}
public String toString()
{
return "User[emp_id="+emp_id+"]";
}
你覺得'setDep_id無法解析或不是字段'的意思?你可以看到錯誤來自哪裏。 –