日期:2014-05-17  浏览次数:20753 次

浏览器访问struts项目的时候一直处于打开状态,但网页就是打不开,控制台也不报错
以下是各个文件代码及配置:

Register.java代码

package controller;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;
import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;


public class Register extends ActionSupport{

private String username;

private File uploadFile;

private String uploadFileFileName;

@Override
public void validate(){

}

public String getUsername(){
return username;
}

public void setUsername(String username){
this.username=username;
}

public File getUploadFile(){
return uploadFile;
}

public void setUploadFile(File uploadFile){
this.uploadFile=uploadFile;
}

public String getUploadFileFileName(){
return uploadFileFileName;
}

public void setUploadFileFileName(String uploadFileFileName){
this.uploadFileFileName=uploadFileFileName;
}

public String execute() throws IOException {

System.out.println("username的值是:"+username);

String targetDirectory=ServletActionContext.getServletContext().getRealPath("/upload");


File target = new File(targetDirectory,uploadFileFileName);

FileUtils.copyFile(uploadFile,target);

return "register";
}
}


struts.xml 配置

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
 "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>

<package name="struts3.1" extends="struts-default" >

<action name="register" class="controller.Register">
<result name="register">showregister.jsp</result>
<result name="input">register.jsp</result>
</action>
</package>

<constant name="struts.ui.theme" value="simple"></constant>
</struts>


register.jsp代码:

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page isELIgnored="false" %>
<%@ taglib uri="/struts-tags" prefix="s" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">