📄 signaction.java
字号:
package com.coffee.StudyBbs;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import javax.servlet.ServletContext;
import javax.sql.DataSource;
import java.sql.Connection;
public final class SignAction extends Action{
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception {
UserForm userform = (UserForm) form;
String username = userform.getUsername();
String password = userform.getPassword();
String nickname = userform.getNickname();
String sex = userform.getSex();
String birthyear = userform.getBirthyear();
String birthmonth = userform.getBirthmonth();
String birthday = userform.getBirthday();
String email = userform.getEmail();
String mobile = userform.getMobile();
String signiture = userform.getSigniture();
ServletContext context = servlet.getServletContext();
DataSource dataSource = (DataSource)context.getAttribute(Constants.DATASOURCE_KEY);
DB db = new DB(dataSource);
User user=new User();
user.setUsername(username);
user.setPassword(password);
user.setNickname(nickname);
user.setSex(sex);
user.setBirthyear(birthyear);
user.setBirthmonth(birthmonth);
user.setBirthday(birthday);
user.setEmail(email);
user.setMobile(mobile);
user.setSigniture(signiture);
String PageForward;
ActionMessages errors = new ActionMessages();
if (!username.equals("guest") && user.Insert(db)) {
PageForward="toLogin"; //新用户注册成功
}
else{ //新用户注册失败
errors.add(ActionMessages.GLOBAL_MESSAGE,
new ActionMessage("errors.registFail"));
if (!errors.isEmpty()) {
saveErrors(request, errors);
}
PageForward="toWrong";
}
db.close();
return mapping.findForward(PageForward);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -