【发布时间】:2011-05-10 19:05:52
【问题描述】:
当我点击一个锚点时,这个问题与上一个问题有关
<a href="#" id="Email">send email</a>
它使用 json 调用 servlet
$("#Email").click(function() {
var option={
"action":"sendEmail"
};
$.getJSON('StudentManagementServlet',option, function(hasEmail) {
if(hasEmail == false){
// //view form to let user enter his email
$("#CommViaEmail").fadeIn("normal");
}
});
});
在 servlet 中我处理请求
if (action != null && action.equals("sendEmail")) {
//open connection to db
con.setAutoCommit(false);
String email = ParentManagement.getParentEmail(con, stdNo);
if (email != null) {
String commResult = createAccountAndSendEmail(con, parentNo, email);
request.setAttribute("result", commResult);
request.setAttribute("incp", "ResultPage");
RequestDispatcher dispatcher = request.getRequestDispatcher("/index.jsp");
dispatcher.forward(request, response); //doesn't make forward!!!!!
System.out.println(">>send email DONE!!");
con.commit();
return;
} else {
boolean hasEmail = false;
String json = new Gson().toJson(hasEmail);
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(json);
}
}
这里的问题是如果用户有一封电子邮件,那么我发送一封电子邮件但请求不会转发到结果页面,即使打印语句被打印“System.out.println(”>>send email DONE!!” );" ??
【问题讨论】: