我使用是SSH框架 ,在web页面点击提交后提示:
com.opensymphony.xwork2.util.logging.commons.CommonsLogger error
SEVERE: Could not find action or result
/book2/progenitor2!register.action
No result defined for action cn.book.action.ProgenitorAction and result input
struts.xml配置如下:
/result.jsp
/person/personCenter.jsp
image/bmp,image/png,image/gif,image/pjpeg,img/jpg
/progenitor.jsp
jsp代码如下:
照片: | height="70px" /> |
/s:form
Action类代码:
public class ProgenitorAction extends ActionSupport {
....
private File file; // File对象
private String fileFileName; // 获取上传文件名
private String fileContentType;
public String register() throws Exception {
Users user=(Users) ServletActionContext.getRequest().getSession().getAttribute("USER");
System.out.println("当前用户:"+user.getUsername());
if(null==user){
this.tag=4;
}else{
if(this.progenitorService.valiUser(user)){
// 取得后缀名
String hou = "";
// 从项目根路径里取得upload文件夹的全路径
String root = ServletActionContext.getRequest().getRealPath("/upload");
System.out.println("fileFileName:"+this.fileFileName);
//判断file不为空的时候执行文件的上传
if (this.file != null &&!"".equals(this.fileFileName)) {
// 当文件名不为空时取得后缀
if (this.fileFileName != null|| this.fileFileName.indexOf(".") != -1) {
hou = this.fileFileName.substring(
this.fileFileName.lastIndexOf(".") + 1).trim()
.toLowerCase();
}
// 获取request对象
HttpServletRequest request = ServletActionContext.getRequest();
// 创建随机数辅助类对象,并传当前IP参数
IPTimeStamp ip = new IPTimeStamp(request.getRemoteAddr());
// 组合文件名
this.fileFileName = ip.getIPTimeStampRand() + "." + hou;
// 根据上传文件创建输入流
InputStream is = new FileInputStream(file);
File destFile = new File(root, fileFileName);
OutputStream os = new FileOutputStream(destFile);
byte[] buffer = new byte[1024];
int length = 0;
while (-1 != (length = is.read(buffer))) {
os.write(buffer, 0, length);
}
os.close();
is.close();
//不为空的时候set为当前图片
progenitor.setPhoto("upload/"+fileFileName);
System.out.println("图片名称为:"+fileFileName);
} else {
// 为空的时候set为默认图片
progenitor.setPhoto(pic);
}
progenitor.setUsers(user);
this.progenitorService.register(progenitor);
this.tag=5;
}else{
this.tag=6;
}
}
return "doresult";
}
}