String img=myFile.getFileName();
   img = conn.ex_chinese(img);
String title=request.getParameter("title");
   title = conn.ex_chinese(title);
String writer=request.getParameter("writer");
   writer = conn.ex_chinese(writer);
String time1=new java.util.Date().toLocaleString();
String content=request.getParameter("content");
   content = conn.ex_chinese(content);  
String insert="INSERT into linkway.news 
(news_title,news_writer,news_content,news_time,news_img) VALUES ('"+title+"','"+writer+"','"+content+"',to_date('"+time1+"','yyyy-mm-dd hh24:mi:ss'),'"+img+"')";
conn.executeUpdate(insert);最后插入数据库的值都是null值,求解.......

解决方案 »

  1.   

    去下载个smartupload来上传你的图像和文本!很好用的,你可以自己看他里面的例子!简单的很!
      

  2.   

    ENCTYPE="multipart/form-data类型的form,是不能用request.getParameter方法获得的,可以用jspsmartupload组件获得,这跟ASP用request.form方法不能获得表单数据一样
      

  3.   

    我正是用jspsmartupload的上传到目录的,但jspsmartupload有什么组件可以取其他表单域的参数值啊,正如上例的title、content等??
      

  4.   

    可以的!
    在你的处理页面加上如下语句:
    Request res = yourSmartUpload.getRequest();
    此时你可在页面上进行调用res.getParameter("title")
    如果你不明白原理就看看servlet相关资料
      

  5.   

    在SmartUpload类中作了如下初始化
    public final void initialize(PageContext pageContext)
            throws ServletException
        {
            m_application = pageContext.getServletContext();
            m_request = (HttpServletRequest)pageContext.getRequest();
            m_response = (HttpServletResponse)pageContext.getResponse();
        }
    并用定义了如下方法:
    private Request m_formRequest;
    public SmartUpload()
        {
            //...
            m_formRequest = new Request();
        }
    public Request getRequest()
        {
            return m_formRequest;
        }
    在upload()方法中有如下调转语句:
        private int m_startData;//开始
        private int m_endData;//结束
    public void upload() throws...
    {
            String fieldName = new String();//字段名
            boolean isFile = false;
            m_totalBytes = m_request.getContentLength();//post的内容字节大小
            m_binArray = new byte[m_totalBytes];
    //...
            if(isFile){//如果是文件}
            else
            {
                    String value = new String(m_binArray, m_startData, (m_endData - m_startData) + 1);
                    m_formRequest.putParameter(fieldName, value);
            }
    //...
    }
      

  6.   

    to poppop(光盘) :按你意思加了上去,但还是有问题,望指教
    =======================================
    <%@ page language="java" contentType="text/html; charset=gb2312"%> 
    <jsp:useBean id="conn" scope="page" class="Webbeans.OraConnection" />
    <jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload" />
    <%%>
    <html>
    <head>
    <title>上传新闻处理</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    </head><body>
    成功保存
    <a href="upnews.jsp">返回</a><br>
    <%
    Request res = yourSmartUpload.getRequest();
    // Variables
    int count=0;         // Initialization
    mySmartUpload.initialize(pageContext);
    // Only allow txt or htm files
    mySmartUpload.setAllowedFilesList("htm,html,txt,jpg,gif,,");
    // Upload
    mySmartUpload.upload(); // Select each file
    // Retreive the current file
    com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(0);
    String img=myFile.getFileName();
       img = conn.ex_chinese(img);
    String title=res.getParameter("title");
       title = conn.ex_chinese(title);
    String writer=res.getParameter("writer");
       writer = conn.ex_chinese(writer);
    String time1=new java.util.Date().toLocaleString();
    String content=res.getParameter("content");
       content = conn.ex_chinese(content);  
    String insert="INSERT into linkway.news (news_title,news_writer,news_content,news_time,news_img) VALUES ('"+title+"','"+writer+"','"+content+"',to_date('"+time1+"','yyyy-mm-dd hh24:mi:ss'),'"+img+"')";
    conn.executeUpdate(insert); // Save it only if this file exists
    if (!myFile.isMissing()) { // Save the files with its original names in a virtual path of the web server       
    myFile.saveAs("/news/img/" + myFile.getFileName());
    // myFile.saveAs("/upload/" + myFile.getFileName(), mySmartUpload.SAVE_VIRTUAL); // sample with a physical path
    // myFile.saveAs("c:\\temp\\" + myFile.getFileName(), mySmartUpload.SAVE_PHYSICAL); //  Display the properties of the current file
    out.println("文件大小 :" + myFile.getSize() + "<BR>");
    out.println("文 件 名 : " + myFile.getFileName() + "<BR>");
    out.println("本地路径 : " + myFile.getFilePathName() + "<BR>");
    out.println("服务器路径: " + myFile.getFilePathName() + "<BR>");
    out.println("文件类型 : " + myFile.getFileExt() + "<BR>"); count ++; } // Display the number of files uploaded 
    out.println(count + " 文件已上传");
    %>
    <%
       
    %>
    </body>
    </html>
      

  7.   

    打错了上边应该是Request res = mySmartUpload.getRequest();
    ===============================================================================
    org.apache.jasper.JasperException: Unable to compile class for JSPAn error occurred at line: 16 in the jsp file: /htgl/upnews_process.jspGenerated servlet error:
        [javac] Compiling 1 source fileC:\Tomcat 5.0\work\Catalina\localhost\_\org\apache\jsp\htgl\upnews_005fprocess_jsp.java:86: cannot resolve symbol
    symbol  : class Request 
    location: class org.apache.jsp.htgl.upnews_005fprocess_jsp
    Request res = mySmartUpload.getRequest();
            ^An error occurred at line: 16 in the jsp file: /htgl/upnews_process.jspGenerated servlet error:
    C:\Tomcat 5.0\work\Catalina\localhost\_\org\apache\jsp\htgl\upnews_005fprocess_jsp.java:86: cannot resolve symbol
    symbol  : variable mySmartUpload 
    location: class org.apache.jsp.htgl.upnews_005fprocess_jsp
    Request res = mySmartUpload.getRequest();
      

  8.   

    以下是Request类,SmartUpload包中应有该类import java.util.Enumeration;
    import java.util.Hashtable;public class Request
    {    private Hashtable m_parameters;
        private int m_counter;    Request()
        {
            m_parameters = new Hashtable();
            m_counter = 0;
        }    protected void putParameter(String name, String value)
        {
            if(name == null)
                throw new IllegalArgumentException("The name of an element cannot be null.");
            if(m_parameters.containsKey(name))
            {
                Hashtable values = (Hashtable)m_parameters.get(name);
                values.put(new Integer(values.size()), value);
            } else
            {
                Hashtable values = new Hashtable();
                values.put(new Integer(0), value);
                m_parameters.put(name, values);
                m_counter++;
            }
        }    public String getParameter(String name)
        {
            if(name == null)
                throw new IllegalArgumentException("Form's name is invalid or does not exist (1305).");
            Hashtable values = (Hashtable)m_parameters.get(name);
            if(values == null)
                return null;
            else
                return (String)values.get(new Integer(0));
        }    public Enumeration getParameterNames()
        {
            return m_parameters.keys();
        }    public String[] getParameterValues(String name)
        {
            if(name == null)
                throw new IllegalArgumentException("Form's name is invalid or does not exist (1305).");
            Hashtable values = (Hashtable)m_parameters.get(name);
            if(values == null)
                return null;
            String strValues[] = new String[values.size()];
            for(int i = 0; i < values.size(); i++)
                strValues[i] = (String)values.get(new Integer(i));        return strValues;
        }
    }
      

  9.   

    也许是版本不同吧,你看看你的SmartUpload类包中是否有类似类定义
      

  10.   

    按你写的,应import com.jspsmart.upload.*
      

  11.   

    我已经解决了,加一句:
    String title=new String(mySmartUpload.getRequest().getParameter("title").getBytes("GBK"),"ISO8859-1");