orward name="agree" path="/RegUser_Agree.jsp"/>
<forward name="apply" path="/RegUser_Apply.jsp"/>
</action>
action-servlet.xml: <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans default-autowire="byName" default-lazy-init="true">
<!-- 按模块导入Spring Action Config-->
<import resource="modules/spring-config-admin.xml"/>
<!-- 简单应用直接在此定义Action
<bean name="/user" class="org.springside.helloworld.web.UserAction"/>
-->
<bean name="/welcome" class="com.xkland.action.WelcomeAction"/>
<bean name="/RegUser" class="com.xkland.action.RegUserAction"/>
</beans>
SpringSide开发实战(六):AJAX,在地狱中漫步(7)
时间:2011-05-07 blogjava 海边沫沫
而这个com.xkland.action.RegUserAction的完整代码如下,希望大家多提意见:
package com.xkland.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
import org.springside.core.web.StrutsAction;
import com.xkland.manager.UserManager;
import com.xkland.util.ImageUtil;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import com.xkland.domain.User;
public class RegUserAction extends StrutsAction {
private ImageUtil imageUtil;
private UserManager userManager;
public void setUserManager(UserManager userManager) {
this.userManager = userManager;
}
public void setImageUtil(ImageUtil imageUtil) {
this.imageUtil = imageUtil;
}
// 重定向到会员注册协议页面
public ActionForward agree(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
return mapping.findForward("agree");
}
// 重定向到填写表单 页面
public ActionForward apply(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
// 使用Token防止重复提交
saveToken(request);
return mapping.findForward("apply");
}
// 构造验证图片
public ActionForward createValidateImage(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) {
BufferedImage image = imageUtil.createValidateImage(request
.getSession());
response.setContentType("image/jpeg");
try {
ImageIO.write(image, "jpeg", response.getOutputStream ());
response.flushBuffer();
} catch (Exception e) {
|