上传图片用到的(js,action)-Hired My way 项目


第一:把上传的图片放到在本地的电脑,也就是你存放图片的服务器上。在当时开发过程中放在本地C:\Apache2.2\htdocs下。而数据库只存图片的名称。(也就是说有专门放图片的一个表(photo),它ID和其他的表字段关联)。

第二:要想显示图片,当时用的先安装Apache。在这个配置文件中定义config.properties

{

floder_for_uploaded_resume=C\:\\Apache2.2\\htdocs
floder_for_uploaded_photo=C\:\\Apache2.2\\htdocs
floder_for_uploaded=http\://localhost/

floder_for_uploaded_resume_size=5242880

}

下面的SysConfig.java 就是读config.properties配置文件

import java.io.InputStream;
import java.util.Properties;

import org.apache.commons.lang.xwork.StringUtils;
import org.hibernate.util.ConfigHelper;

public class SysConfig {
    private static final String CONFIG = "config.properties";
    private static Properties p;

    static {
//        String path = Thread.currentThread().getContextClassLoader()
//                .getResource("").getPath();
        try {
//            FileInputStream config = new FileInputStream(path + CONFIG);
            InputStream input = ConfigHelper.getConfigStream(CONFIG);
            //FileInputStream config = new FileInputStream(input);
            p = new Properties();
            p.load(input);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static String getItem(String key) {
         String result =p.getProperty(key.toLowerCase(), "");
         if(StringUtils.isEmpty(result)){
             result =p.getProperty(key, "");
         }
         AddLog.addToLog(SysConfig.class,AddLog.DEBUG,"get config of '"+key+"' from file value:"+result);
         return result;
    }
    
    public static Integer getInteger(String key) {
        String value = SysConfig.getItem(key);
        Integer result = null;
        if (value != null && value.length() > 0) {
            result = Integer.parseInt(value);
        }
        return result;
    }
    
    public static Boolean getBoolean(String key) {
        String value = SysConfig.getItem(key);
        Boolean result = false;
        if (value != null && value.length() > 0) {
            if(value.trim().equals("true")){
                result = true;
            }
        }
        return result;
    }
}

=====================================%%%%%%%%%%%%%%%%%%%%

在struts.xml中定义UploadAction allowType是参数 通过get set 方法

        <action name="uploadImage" class="com.hiredmyway.action.util.UploadAction" method="uploadImage">
            <param name="allowType">jpg,jpeg,bmp,png,gif</param>
            <result name="input">/common/error.jsp</result>
            <interceptor-ref name="fileUpload">
            </interceptor-ref>
            <interceptor-ref name="myDefaultStack"></interceptor-ref>
        </action>

-------------------==============================================

以上的文件我都在我的电脑中




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值