smartupload.jar已导入,服务器:weblogic9.2
报错如下:
Compilation of JSP File '/test.jsp' failed:
--------------------------------------------
test.jsp:18:21: No match was found for method getServletContext() in type jsp_servlet.__test.
String fileName = this.getServletContext().getRealPath("/") + "upload/" + name ;
^----------------------^
test.jsp:18:21: No match was found for method getRealPath(java.lang.String) in type <error>.
String fileName = this.getServletContext().getRealPath("/") + "upload/" + name ;
^---------------------------------------^
test.html:
<html>
<head>
<title>smartupload</title>
</head>
<body>
<form action="test.jsp" method="post" enctype="multipart/form-data">
文件名称:<input type="text" name="uname"><br>
上传的图片:<input type="file" name="pic"><br>
<input type="submit" value="上传">
</form>
</body>
</html>
test.jsp:
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%@ page import="java.io.*"%>
<jsp:useBean id="smartupload" class="com.jspsmart.upload.SmartUpload"/>
<html>
<head>
<title>smartupload</title>
</head>
<body>
<%
request.setCharacterEncoding("GBK") ;
smartupload.initialize(pageContext) ; // 初始化上传
smartupload.upload() ; // 准备上传
String name = smartupload.getRequest().getParameter("uname") ;
name = name + "." + smartupload.getFiles().getFile(0).getFileExt() ;
String fileName = this.getServletContext().getRealPath("/") + "upload/" + name ;
smartupload.getFiles().getFile(0).saveAs(fileName) ;
%>
</body>
</html>
------解决方案--------------------
this.getServletContext().getRealPath("/")
换成:
application.getRealPath("/") 试试
------解决方案--------------------
你的开发工具是什么?myeclips就不存在路径问题,而用eclips开发时,具体原因不知道,但是路径有问题的,你把路径写成绝对的试试!我以前遇到过