我正在使用netbeans IDE开发JAVA Web项目,我希望在项目目录之外的文件夹中显示一些图像,在我的servlet上传之后,这是我的代码:
的web.xml:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
UIApplication.sharedApplication().statusBarStyle = .LightContent
UINavigationBar.appearance().titleTextAttributes = [NSFontAttributeName: (UIFont(name: "AvenirNext-DemiBold", size: 50.0))!]
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName : UIColor(red: 244/255, green: 234/255, blue: 166/255, alpha: 1.0)]
return true
}
img in jsp:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>views/index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>login</servlet-name>
<servlet-class>controllers.LoginController</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>login</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>index</servlet-name>
<jsp-file>/views/index.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>index</servlet-name>
<url-pattern>/index</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>students</servlet-name>
<servlet-class>controllers.StudentController</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>students</servlet-name>
<url-pattern>/students</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>books</servlet-name>
<servlet-class>controllers.BookController</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>books</servlet-name>
<url-pattern>/books</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>admins</servlet-name>
<servlet-class>controllers.AdminController</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>admins</servlet-name>
<url-pattern>/admins</url-pattern>
</servlet-mapping>
<context-param>
<param-name>uploads</param-name>
<param-value>C:/Users/mohammad/Documents/NetBeansProjects/uploads</param-value>
</context-param>
</web-app>
的servlet:
我将它发送到json对象中:
<img src="C:/Users/mohammad/Documents/NetBeansProjects/uploads/name.jpg"/>
我确信该图片存在于该文件夹中,但无法加载,这里有什么问题?
答案 0 :(得分:0)
你应该在web.XML图像扩展文件上添加过滤器,它实际上指定了哪种外部资源可以通过前端控制器传递。请你发布你的web.xml
您可以尝试此链接Upload an image to a Path set in web.xml using primefaces