java练习

貢獻者:游客19251134 類別:代码 時間:2017-05-04 18:58:49 收藏數:9 評分:0.5
返回上页 舉報此文章
请选择举报理由:




收藏到我的文章 改錯字
package com.itcast.action;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import com.itcast.domain.User;
import com.itcast.service.UserService;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
@Controller
@Scope("pototype")
@Namespace("/")
@ParentPackage("struts-default")
public class UserAction extends ActionSupport implements ModelDriven<User>{
/**
*
*/
private static final long serialVersionUID = 1L;
private User user = new User();
private File userImage;
private String userImageContentType;
private String userImageFileName;
@Autowired
private UserService userService;
@Override
public User getModel() {
return user;
}
public File getUserImage() {
return userImage;
}
public void setUserImage(File userImage) {
this.userImage = userImage;
}
public String getUserImageContentType() {
return userImageContentType;
}
public void setUserImageContentType(String userImageContentType) {
this.userImageContentType = userImageContentType;
}
public String getUserImageFileName() {
return userImageFileName;
}
public void setUserImageFileName(String userImageFileName) {
this.userImageFileName = userImageFileName;
}
@Action(value="userRegist",results={@Result(name="success",location="/jsp/login.jsp"),
@Result(name="input",location="/jsp/msg.jsp")})
public String userRegist(){
//处理上传文件
try {
File destFile=new File(ServletActionContext.getServletContext().
getRealPath("/upload"),userImageFileName);
FileUtils.copyFile(userImage, destFile);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//将上传文件封装进user
String userImgSrc=ServletActionContext.getRequest().getContextPath()+"/upload"+userImageFileName;
user.setUserImgSrc(userImgSrc);
int count=userService.userRegist(user);
System.out.println(count);
return SUCCESS;
}
/*public String findAllCustomer(){
List<Customer> customer=customerService.findAllCustomer();
//System.out.println(customer);
ActionContext.getContext().getValueStack().set("customer", customer);
return SUCCESS;
}*/
@Action(value="userLogin",results={@Result(name="success",location="/index.jsp")})
public String userLogin(){
User loginUser = userService.login(user);
if(loginUser==null){
System.out.println("登录失败");
}else{
ServletActionContext.getRequest().setAttribute("loginUser", loginUser);
return SUCCESS;
}
return null ;
}
}
声明:以上文章均为用户自行添加,仅供打字交流使用,不代表本站观点,本站不承担任何法律责任,特此声明!如果有侵犯到您的权利,请及时联系我们删除。
文章熱度:
文章難度:
文章質量:
說明:系統根據文章的熱度、難度、質量自動認證,已認證的文章將參與打字排名!

本文打字排名TOP20

登录后可见

用户更多文章推荐