请问我提交一个表单后,IE的URL上面就会出现文件名.do,但是它怎么都没有执行return(mapping.findForward("success"));和return(mapping.findForward("error"));}数据库中也没有加入数据.请问怎么去判断这个错误,同时请问一下大家在刚学这个的时候一般是怎么去找错误和调试程序的,介绍一下大家的方法小弟在这里先谢谢了!public class AddemployeeAction extends Action {
public ActionForward execute(ActionMapping mapping,HttpServletRequest request,HttpServletResponse response,ActionForm form) throws Exception{
EmployeeBean service=new EmployeeBean();
EmployeeForm employeeForm=(EmployeeForm)form;
Employee employee=new Employee();
employee=employeeForm.getEmployee(); try{
service.addEmployee(employee);
ActionMessages messages=new ActionMessages();
messages.add(ActionMessages.GLOBAL_MESSAGE,new ActionMessage(""));
saveMessages(request,messages);
request.setAttribute("employee", employee);
return(mapping.findForward("success"));
}catch(Exception e){
ActionErrors errors=new ActionErrors();
errors.add(ActionErrors.GLOBAL_ERROR,new ActionError(""));
saveErrors(request,errors);
return(mapping.findForward("error"));}
}}
这是数据库的链接
public class DatabaseConn {
public static Connection getConnection(){
Connection conn=null;
final String CLASSFORNAME="com.microsoft.jdbc.sqlserver.SQLServerDriver";
final String SERANDDB="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=jspdve";
final String USER="bn";
final String PWD="bn";
try{
Class.forName(CLASSFORNAME);
conn=DriverManager.getConnection(SERANDDB,USER,PWD);
}catch(final Exception e){
e.printStackTrace();
}
return conn;
}
}
这个是Bean public void addEmployee(Employee employee)throws Exception{
this.exectuteHelper("insert into employee values('"+employee.getId()+"','"+employee.getName()+"','"+employee.getSalary()+"','"+employee.getAge()+"')");
}private void exectuteHelper(String sql)throws Exception{
Statement stmt=conn.createStatement();
stmt.executeUpdate(sql);
}
这个是*.XML文件<form-bean name="employeeForm" type="com.jspdev.ch17.EmployeeForm" />
</form-beans>
<global-exceptions />
<global-forwards />
<action-mappings>
<action
name="employeeForm"
path="/createEmployee"
scope="request"
input="/createEmployee.jsp"
type="com.jspdev.ch17.AddemployeeAction">
<forward name="success" path="/employeeCreated.jsp" />
<forward name="error" path="/error.jsp"></forward>
</action>
public ActionForward execute(ActionMapping mapping,HttpServletRequest request,HttpServletResponse response,ActionForm form) throws Exception{
EmployeeBean service=new EmployeeBean();
EmployeeForm employeeForm=(EmployeeForm)form;
Employee employee=new Employee();
employee=employeeForm.getEmployee(); try{
service.addEmployee(employee);
ActionMessages messages=new ActionMessages();
messages.add(ActionMessages.GLOBAL_MESSAGE,new ActionMessage(""));
saveMessages(request,messages);
request.setAttribute("employee", employee);
return(mapping.findForward("success"));
}catch(Exception e){
ActionErrors errors=new ActionErrors();
errors.add(ActionErrors.GLOBAL_ERROR,new ActionError(""));
saveErrors(request,errors);
return(mapping.findForward("error"));}
}}
这是数据库的链接
public class DatabaseConn {
public static Connection getConnection(){
Connection conn=null;
final String CLASSFORNAME="com.microsoft.jdbc.sqlserver.SQLServerDriver";
final String SERANDDB="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=jspdve";
final String USER="bn";
final String PWD="bn";
try{
Class.forName(CLASSFORNAME);
conn=DriverManager.getConnection(SERANDDB,USER,PWD);
}catch(final Exception e){
e.printStackTrace();
}
return conn;
}
}
这个是Bean public void addEmployee(Employee employee)throws Exception{
this.exectuteHelper("insert into employee values('"+employee.getId()+"','"+employee.getName()+"','"+employee.getSalary()+"','"+employee.getAge()+"')");
}private void exectuteHelper(String sql)throws Exception{
Statement stmt=conn.createStatement();
stmt.executeUpdate(sql);
}
这个是*.XML文件<form-bean name="employeeForm" type="com.jspdev.ch17.EmployeeForm" />
</form-beans>
<global-exceptions />
<global-forwards />
<action-mappings>
<action
name="employeeForm"
path="/createEmployee"
scope="request"
input="/createEmployee.jsp"
type="com.jspdev.ch17.AddemployeeAction">
<forward name="success" path="/employeeCreated.jsp" />
<forward name="error" path="/error.jsp"></forward>
</action>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货