本帖最后由 wj6659815 于 2012-03-28 23:34:25 编辑

解决方案 »

  1.   

    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <!--
    body {
    FONT-SIZE: 9pt;
    margin-left:0px;
    margin-top:0px;
    SCROLLBAR-FACE-COLOR: #622949; 
    SCROLLBAR-HIGHLIGHT-COLOR: #ffffff;
    SCROLLBAR-SHADOW-COLOR: #fcfcfc; COLOR: #000000;
    SCROLLBAR-3DLIGHT-COLOR: #ececec;
    SCROLLBAR-ARROW-COLOR: #ffffff;
    SCROLLBAR-TRACK-COLOR: #ececec;
    SCROLLBAR-DARKSHADOW-COLOR: #999966;
    }.topA{
        font-size:9pt;color:#63284A;
        text-decoration:none;
    }
    .topA:hover{
    font-size: 9pt; color: #000000;
    text-decoration:underline
    }
    a {
    font-size: 9pt; text-decoration: none; color:  #6E6E6E;
    noline:expression(this.onfocus=this.blur);
    }
    a:hover {
    font-size: 9pt; color: #410E3D;
    text-decoration:underline
    }
    .word_white {
    font-size: 9pt;
    color: #FFFFFF;
    }
    .word_purple {
    font-size: 9pt;
    color: #BB71A6;
    }
    .word_menuHead{
    font-size: 9pt;
    color: #62294A;
    font-weight:bold;
    }
    .topTD{
    font-size: 9pt; color: #63284A;
    }
    td{
    font-size: 9pt; color: #655555;
    }
    input{
    font-family: "宋体";
    font-size: 9pt;
    color: #333333;
    background-color:#F9EFF6;}
    body {
    margin-left: 0px;
    margin-top: 20px;
    margin-right: 0px;
    margin-bottom: 0px;
    }
    .textarea {
    font-family: "宋体";
    font-size: 9pt;
    color: #333333;
    border: 1px solid #999999;
    }
    .btn_bg {
    background-image:url(../images/btn_bg.jpg); border:#436E9B thin 1px;
    width:48px;
    height:20px;padding:4px;
    color:#FFFFFF;
    }
    .tableBorder_B{
    border:1px dotted #E59FD5;
    border-left-style:none; 
    border-right-style:none;
    border-Top-style:none; 
    }
    .tableBorder_R{
    border:1px dotted #622949;
    border-left-style:none; 
    border-bottom-style:none;
    border-Top-style:none; 
    }
    .tableBorder_T{
    border:1px dotted #622949;
    border-left-style:none; 
    border-right-style:none;
    border-bottom-style:none; 
    }
    .noborder{
    border-style:none;
    background-color:#FFFFFF;
    }
    -->
      

  2.   

    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <!--
    .topA{
        font-size:9pt;color:#63284A;
        text-decoration:none;
    }
    .topA:hover{
    font-size: 9pt; color: #000000;
    text-decoration:underline
    }
    a {
    font-size: 9pt; text-decoration: none; color: #6E6E6E;
    noline:expression(this.onfocus=this.blur);
    }
    a:hover {
    font-size: 9pt; color: #000000;
    text-decoration:underline
    }
    .topTD{
    font-size: 9pt; color: #63284A;
    }
    td{
    font-size: 9pt; color: #655555;
    }
    input{
    font-family: "宋体";
    font-size: 9pt;
    color: #333333;
    background-color:#F9EFF6;}
    body {
    margin-left: 0px;
    margin-top: 20px;
    margin-right: 0px;
    margin-bottom: 0px;
    }
    .textarea {
    font-family: "宋体";
    font-size: 9pt;
    color: #333333;
    border: 1px solid #999999;
    }
    .btn_bg {
    background-image:url(../images/btn_bg.jpg); border:#436E9B thin 1px;
    width:48px;
    height:20px;padding:4px;
    color:#FFFFFF;
    }-->
      

  3.   

    Struts2上传文件
    upload.jsp
    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%@ taglib prefix="s" uri="/struts-tags" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      ……
      <body>
       <s:form action="upload.action" enctype="multipart/form-data">
       <s:file name="img" ></s:file>
       <s:submit name="sub" value="upLoad"></s:submit>
       </s:form>
      </body>
    </html>UploadAction:
    public class UploadFileAction extends ActionSupport {
    private File img; //img变量用于接收上传的文件
    private String imgFileName;//上传的文件名,即img+“FileName”
    private String imgContextType;
    public File getImg() {
    return img;
    }
    public void setImg(File img) {
    this.img = img;
    }
    public String getImgFileName() {
    return imgFileName;
    }
    public void setImgFileName(String imgFileName) {
    this.imgFileName = imgFileName;
    }
    public String getImgContextType() {
    return imgContextType;
    }
    public void setImgContextType(String imgContextType) {
    this.imgContextType = imgContextType;
    }
    @Override
    public String execute() throws Exception {
    System.out.println("<><><>上传……<><><>");
    File imageFile = new File(ServletActionContext.getServletContext().getRealPath("/upload")+
      "/"+imgFileName);  //上传的文件保存的路径
    InputStream in = new FileInputStream(img); //建立读取上传文件的输入流
    OutputStream out = new FileOutputStream(imageFile); //建立指向目标位置的输出流
    byte[] buff = new byte[1024];
    int len = 0;
    while ((len = in.read(buff)) != -1) {         //读取源文件并写入到目标文件夹中
    out.write(buff, 0, len);
    }
    in.close();
    out.close();
    return SUCCESS;
    }
    }