js部分代码
//添加或者修改的提交信息
function submitStu(){
//使用form提交数据
$('#studentInfo_form').form('submit',{
url:'student_Info.action',
//success提交成功时触发,函数括号内是回带的数据
success:function(result){
//自定义封装的js消息框函数
showMessage(result);
if($('#stuId').val()=='0'){
//如果时增加就全查
findAll();
}else{
//否则刷新本页数据
$('#stutab').datagrid('reload');
}
}
});
}
java后台处理的部分代码
public void studentInfo(){
String result="";
try{
if(stu.getStuId()==0){
this.resultMsg=ss.insertStudent(stu);
}else{
this.resultMsg=ss.updateStudent(stu);
}
request.getSession().setAttribute("find", "find");
//设置编码
response.setContentType("text/html;charset=UTF-8");
//回带数据
response.getWriter().write(this.resultMsg);
}catch(SQLException e){
this.setResultMsg("数据库查询异常");
result="errorSQL";
}catch(Exception e){
result="error";
this.setResultMsg("逻辑有问题");
}
}
struts配置部分代码
<package name="study" extends="json-default">
<action name="student_Info" class="cn.eduask.action.StudyAction" method="studentInfo">
</action>
</package>