静态页面:<script language=javascript src="../../javascript/checkKFpicture.js"></script><link charset="GBK" href="../../css/register.css" rel="stylesheet"
type="text/css" />
<form action="KFpictureCheck.jsp" method="post" enctype="multipart/form-data">
<table width="100%" border="0" align="center" cellpadding="0"
cellspacing="0">
<tr>
<td height="30">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="15" height="30">
<img src="images/tab_03.gif" width="15" height="30" />
</td>
<td width="1101" background="images/tab_05.gif">
<img src="images/311.gif" width="16" height="16" />
<span class="STYLE4">添加康复网图片</span>
</td>
<td width="281" background="images/tab_05.gif">&nbsp;
</td>
<td width="14">
<img src="images/tab_07.gif" width="14" height="30" />
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="9" background="images/tab_12.gif">&nbsp;
</td>
<td bgcolor="#f3ffe3">
<table width="100%" border="0" cellspacing="0" cellpadding="2">
<tr>
<td width="24%" align="right" class="A">
<span class="Personreg-text12r">*康复网</span>图片名
</td> <td width="28%">
  <input type="text" name="pictureName" id="pictureName" />
        </td>
<td width="48%">
<table id="zhuce1" width="100%" border="0" cellpadding="0"
cellspacing="0" bgcolor="#F7FFE7">
<tr>
<td width="3%" height="50" class="STYLE4">
</td>
<td width="97%" class="STYLE4">
图片名是每个图片都应该有的名字,您可以随便取,但不能为空,这是对图片的标示。
</td>
</tr>
</table>
</td>
</tr>
                    
          
                                <tr>
<td width="24%" align="right" class="A">
<span class="Personreg-text12r">*</span>图片超连接</td> <td width="28%"><input type="text" name="show" id="show" /></td>
<td width="48%">
<table id="zhuce1" width="100%" border="0" cellpadding="0"
cellspacing="0" bgcolor="#F7FFE7">
<tr>
<td width="3%" height="50" class="STYLE4">
</td>
<td width="97%" class="STYLE4">
点击这个图片应该跳到什么地方?例如:超级连接到百度:http://www.baidu.com</td>
</tr>
</table>
</td>
</tr>
                                <tr>
<td width="24%" align="right" class="A">
  <span class="Personreg-text12r">*</span>图片选择</td> <td width="28%">
      <input type="file" name="picture" id="picture" /></td>
<td width="48%">
<table id="zhuce1" width="100%" border="0" cellpadding="0"
cellspacing="0" bgcolor="#F7FFE7">
<tr>
<td width="3%" height="50" class="STYLE4">
</td>
<td width="97%" class="STYLE4">选择您要上传的图片,此图片格式应该为.gif/jpg;大小应该为:469px*69px;文件大小应小于70kb。</td>
</tr>
</table>
</td>
</tr>
                                <tr>
<td height="50" align="center"></td>
<td align="center">
<input class="STYLE3" type="submit" name="submit" value="提交" />
<input type="reset" class="STYLE3" name="reset" value="重置" />
</td>
<td align="center">&nbsp;

</td>
</tr>
</table>
  </td>
<td width="9" background="images/tab_16.gif">&nbsp;
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td height="29">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="15" height="29">
<img src="images/tab_20.gif" width="15" height="29" />
</td>
<td background="images/tab_21.gif">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="25%" height="29" nowrap="nowrap">&nbsp;
</td>
<td width="75%" valign="top" class="STYLE1">
<div align="right">
<table width="92" height="20" border="0" cellpadding="0"
cellspacing="0">
<tr>
<td width="62" height="22" valign="middle">&nbsp;
</td>
<td width="30" height="22" valign="middle">&nbsp;
</td>
</tr>
                                                
</table>
</div>
</td>
</tr>
</table>
</td>
<td width="14">
<img src="images/tab_22.gif" width="14" height="29" />
</td>
</tr>
</table>
</td>
</tr>
</table>
    </form>执行页面:
<%@ page language="java"
import="java.util.*"
pageEncoding="GBK"%>
<jsp:directive.page import="myjava.mycompany.operate.FileUploadTools;"/>
<%
    request.setCharacterEncoding("GBK");
%><html>
  <head>
    <title>康复网图片上传</title>
  </head>
  <body>     
    <%
    FileUploadTools fut=new FileUploadTools(request,70*1024,this.getServletContext().getRealPath("/")+"uploadtemp");
    String pictureName = fut.getParameter("pictureName");
    String show = fut.getParameter("show");
    List <String> all = fut.saveAll(this.getServletContext().getRealPath("/")+"upload"+java.io.File.separator); 
    %>
    <h3><%=pictureName %></h3>
    <h3><%=show %></h3>
    <%
    Iterator <String> iter=all.iterator();
    while(iter.hasNext()){
    %>
    <img src="../upload/<%=iter.next()%>"/>
    <%
    }
    %>
  </body>
</html>类:
package myjava.mycompany.operate;
import java.util.*;
import java.io.*;
import javax.servlet.http.*;
import org.apache.commons.fileupload.*;
import org.apache.commons.fileupload.disk.*;
import org.apache.commons.fileupload.servlet.*;
public class FileUploadTools {
private HttpServletRequest request=null;
private List<FileItem> items=null;
private Map<String,List<String>> params= new HashMap<String,List<String>>() ;
private Map<String, FileItem> files=new HashMap<String,FileItem>();
public FileUploadTools(HttpServletRequest request,int maxSize,String tempDir)throws Exception{
this.request=request;
DiskFileItemFactory factory=new DiskFileItemFactory();
if(tempDir!=null){
factory.setRepository(new File(tempDir));
}
ServletFileUpload upload=new ServletFileUpload(factory);
if(maxSize>0){
upload.setFileSizeMax(maxSize);
}
this.items=upload.parseRequest(request);
this.init();
}
private void init(){
Iterator<FileItem> iter=this.items.iterator();
IPTimeStamp its=new IPTimeStamp(this.request.getRemoteAddr());
while(iter.hasNext()){
FileItem item=iter.next();
if(item.isFormField()){//普通参数
String name=item.getFieldName();
String value=item.getString();
List<String>temp=null;
if(this.params.containsKey(name)){
temp=this.params.get(name);
}else{
temp=new ArrayList<String>();
}
temp.add(value);
this.params.put(name, temp);
}else{
String fileName=its.getIPTimeRand()+"."+item.getName().split("\\.")[1];
    this.files.put(fileName, item);
}
}
}
public String getParameter(String name){//根据参数名称取出内容
String ret=null;
List<String> temp=this.params.get(name);
if(temp!=null){
ret=temp.get(0);
}
return ret;
}
public String[]getParameterValues(String name){
String ret[]=null;
List <String >temp=this.params.get(name);
if(temp!=null){
ret=temp.toArray(new String[]{});
}
return ret;
}
public Map<String,FileItem> getUploadFiles(){
return this.files;
}
//保存之后一定要有名字。
public List<String> saveAll(String saveDir) throws IOException{
List<String> names=new ArrayList<String>();
if(this.files.size()>0){
Set<String> keys=this.files.keySet();
Iterator<String> iter=keys.iterator();
File saveFile=null;
InputStream input=null;
OutputStream out=null;
while(iter.hasNext()){
FileItem item=this.files.get(iter.next());
String fileName=new IPTimeStamp(request.getRemoteAddr()).getIPTimeRand()+"."+item.getName().split("\\.")[1];
saveFile =new File(saveDir+fileName);
names.add(fileName);//名字不返回后期无法操作
try{
input=item.getInputStream();
out=new FileOutputStream(saveFile);
byte data[]=new byte[512];
while((input.read(data,0,512))!=-1){
out.write(data);
}
}catch(IOException e){
throw e;
}finally{
try{
input.close();
out.close();
}catch(IOException ex){
throw ex;
}
}
}
}
return names;
}
}

解决方案 »

  1.   

    报错:
    HTTP Status 500 - --------------------------------------------------------------------------------type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: Unable to compile class for JSPAn error occurred at line: 14 in the jsp file: /admin/web/KFpictureCheck.jsp
    Generated servlet error:
    Syntax error on token "<", invalid AssignmentOperatorAn error occurred at line: 14 in the jsp file: /admin/web/KFpictureCheck.jsp
    Generated servlet error:
    Syntax error on token "=", != expectedAn error occurred at line: 22 in the jsp file: /admin/web/KFpictureCheck.jsp
    Generated servlet error:
    Syntax error on token "<", invalid AssignmentOperatorAn error occurred at line: 22 in the jsp file: /admin/web/KFpictureCheck.jsp
    Generated servlet error:
    Syntax error on token "=", != expected
    org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
    org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
    org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:386)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:280)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:259)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:247)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:556)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:296)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:245)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    note The full stack trace of the root cause is available in the Apache Tomcat/5.5.3 logs.
    --------------------------------------------------------------------------------Apache Tomcat/5.5.3
      

  2.   

    代码真长 我的理智和直觉都告诉我 你的jsp页面 14行附近的那个表格 <tr>和<td>没有配对..
      

  3.   

    是了 看看那<table>下的第一个和第二个<tr> 没配对 你再仔细检查一下
      

  4.   

    根据报的错误,追踪一下,看到底是jsp的问题还是服务器的问题,首先要找到问题的根本所在……
      

  5.   

    lz你貌似这个jsp的标准动作用的不对吧:<jsp:directive.page import="myjava.mycompany.operate.FileUploadTools;"/>