返回首页


在大部分项目中,我们试图捕捉到用户在网页上的脸。直到最近,许多项目已经实施使用或者ActiveX对象或使用Java插件或其他一些媒体的插件。闪光灯及其相关技术的问世,这和其存在的增加,在Web闪光灯已成为最喜爱的技术来构建这样的应用,从而使其浏览器的不可知相比,ActiveX对象。
有一个名为JPEGCam的网页,这是自由和开放源码和有能力这样做的项目。
我的努力是创建一个Java后端,其前端(默认情况下是一个用PHP后端)。以下举例说明我的努力。
我创建了一个mavenized应用程序,使其运行没有任何额外的服务器部署。这里是描述。
我已经创建了一个简单的servlet刚刚捕获的输入流,数据存储在一个文件夹名为上传,文件的URL发送回客户端显示。
下面是代码:

package com.linkwithweb.jpegcam;



import java.io.File;

import java.io.FileOutputStream;

import java.io.IOException;

import java.util.Date;



import javax.servlet.Servlet;

import javax.servlet.ServletConfig;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;



/**

 * Ashwin Kumar

 * Servlet implementation class PictureCaptureServlet

 */

public class PictureCaptureServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	private String fileStoreURL = "";



	/**

	 * @see HttpServlet#HttpServlet()

	 */

	public PictureCaptureServlet() {

		super();

		// TODO Auto-generated constructor stub

	}



	/**

	 * @see Servlet#init(ServletConfig)

	 */

	public void init(ServletConfig config) throws ServletException {

		fileStoreURL = config.getServletContext().getRealPath("") + "/uploads";

		try {

			File f = new File(fileStoreURL);

			if (!f.exists()) {

				f.mkdirs();

			}

		} catch (Exception e) {

			// TODO: handle exception

		}

	}



	/**

	 * @see HttpServlet#service(HttpServletRequest request, 

		HttpServletResponse response)

	 */

	protected void service(HttpServletRequest request,

			HttpServletResponse response) throws ServletException, 

				IOException {

		try {

			long time = new Date().getTime();



			FileOutputStream fileOutputStream = new FileOutputStream(

					fileStoreURL + "/"+time+".jpg");

			int res;

			while ((res = request.getInputStream().read()) != -1) {

				fileOutputStream.write(res);

			}

			fileOutputStream.close();

			/**

			 * To make sure each url is different and 

			 * not cached added time to it

			 */

			response.getWriter().append(

					"http://localhost:8080/uploads/" + time

							+ ".jpg");



		} catch (Exception e) {

			e.printStackTrace();

		} finally {



		}

	}

}

下面是一个示例的JavaScript处理的前端:{C}
现在让我贴上我的pom.xml:
<project xmlns=http://maven.apache.org/POM/4.0.0 

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 

	http://maven.apache.org/maven-v4_0_0.xsd">

	<modelVersion>4.0.0</modelVersion>

	<groupId>com.linkwithweb.browsercam</groupId>

	<artifactId>JPEGCamIntegration</artifactId>

	<packaging>war</packaging>

	<version>0.0.1-SNAPSHOT</version>

	<name>JPEGCamIntegration Maven Webapp</name>

	<url>http://maven.apache.org</url>

	<dependencies>

		<dependency>

			<groupId>junit</groupId>

			<artifactId>junit</artifactId>

			<version>3.8.1</version>

			<scope>test</scope>

		</dependency>

		<dependency>

			<groupId>javax.servlet</groupId>

			<artifactId>servlet-api</artifactId>

			<version>2.5</version>

			<scope>provided</scope>

		</dependency>

	</dependencies>

	<build>

		<finalName>JPEGCamIntegration</finalName>

		<plugins>

			<plugin>

				<groupId>org.mortbay.jetty</groupId>

				<artifactId>jetty-maven-plugin</artifactId>

				<version>8.0.0.M2</version>

				<configuration>

					<scanIntervalSeconds>3</scanIntervalSeconds>

				</configuration>

			</plugin>



			<!-- Facilitates downloading source and javadoc in Eclipse -->

			<plugin>

				<groupId>org.apache.maven.plugins</groupId>

				<artifactId>maven-eclipse-plugin</artifactId>

				<version>2.8</version>

				<configuration>

					<wtpversion>2.0</wtpversion>

					<downloadSources>true</downloadSources>

					<downloadJavadocs>true</downloadJavadocs>

				</configuration>

			</plugin>



			<!-- Ensures we are compiling at 1.6 level -->

			<plugin>

				<groupId>org.apache.maven.plugins</groupId>

				<artifactId>maven-compiler-plugin</artifactId>

				<version>2.3.2</version>

				<configuration>

					<source>1.6</source>

					<target>1.6</target>

				</configuration>

			</plugin>

		</plugins>

	</build>

</project>

这里是你如何运行和测试:
mvn jetty:run-exploded

,点击这个URL:{A}
代码已检查到以下位置:{A2}
{A3} {七}

回答

评论会员:Wonde德斯 时间:2012/01/27
在{A4}的外观。]第

好运气
评论会员:Theingi运 时间:2012/01/27
你应该研究这些链接
{A5}
{A6}

希望有所帮助,
Theingi运