当我使用此控制器代码时:
public class BuisnessController {
private Logger logger = Logger.getLogger(BuisnessController.class);
public void addbuisnessimage(HttpServletRequest request,
HttpServletResponse response, String bpath) {
String ret = ""; // For User Registration and File upload code
String business = "";
String subbuisn = "";
String image_file = "";
try {
if (request.getContentType().indexOf("multipart/form-data") != -1) {
List list = new ServletFileUpload(new DiskFileItemFactory())
.parseRequest(request);
java.util.Iterator it = list.iterator();
while (it.hasNext()) {
FileItem fl = (FileItem) it.next();
if (fl.isFormField()) {
String fname = fl.getFieldName();
String fval = fl.getString();
if (fname.equalsIgnoreCase("business")) {
business = fval;
} else if (fname.equalsIgnoreCase("image_file")) {
image_file = fval;
} else if (fname.equalsIgnoreCase("subbuisn")) {
subbuisn = fval;
}
} else {
String filename = fl.getName();
File file = new File(bpath,"images");
file.mkdirs();
String basepath = file.getAbsolutePath();
long t = 0;
String ext = "error";
try {
t = new java.util.Date().getTime();
int l = filename.lastIndexOf(".");
ext = filename.substring(l, filename.length());
String fpath = basepath + "/" + t + ext;
File f = new File(fpath);
fl.write(f);
} catch (Exception e) {
e.printStackTrace();
}
BuisnessImageDTO adminRoleDTO2 = new BuisnessImageDTO();
adminRoleDTO2.setBusiness(business);
adminRoleDTO2.setSubbuisn(subbuisn);
adminRoleDTO2.setImage_file(image_file);
if (ext.equalsIgnoreCase("error")) {
adminRoleDTO2.setImage_file("NA");
} else {
adminRoleDTO2.setImage_file(+t + ext);
}
ret = new BuisnessService().addbuisnessimage(adminRoleDTO2);
}
}
}
if (ret.equalsIgnoreCase("success")) {
request.getRequestDispatcher("buisness-add.jsp").forward(request, response);
} else {
request.getRequestDispatcher("buisness-add.jsp").forward(request, response);
}
} catch (Exception e) {
e.printStackTrace();
logger.error("Data Missing", e);
logger.warn("This is a warning message");
logger.trace("This message will not be logged since log level is set as DEBUG");
try {
request.getRequestDispatcher("buisness-add.jsp").forward(request, response);
} catch (Exception ex) {
ex.printStackTrace();
logger.error("IOEXception occured:", ex);
}
}
}
在我的本地Tomcat上它可以正常工作,但是当我在服务器上部署我的网站时,它会为每个文件夹提供绝对路径错误。即便如此,我也无法获取图像格式数据库。它只显示图像ID,如12356.jsp。我正在使用javax.servlet.jsp.jstl 1.2.1 jar
这是我的xml代码:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>NewAuthentication</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<error-page>
<error-code>404</error-code>
<location>/AppErrorHandler</location>
</error-page>
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/AppErrorHandler</location>
</error-page>
<context-param>
<param-name>log4j-config</param-name>
<param-value>WEB-INF/log4j.xml</param-value>
</context-param>
<session-config>
<session-timeout>100</session-timeout>
</session-config>
<listener>
<listener-class>com.haani.atp.group.listener.MyListener</listener-class>
</listener>
</web-app>
请给我一些建议,因为这是我第一次部署任何网站。