「java服务器接收」java服务器接收多线程
今天给各位分享java服务器接收的知识,其中也会对java服务器接收多线程进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
- 1、Java服务器怎么接收手机上传过来的文件。求具体代码,谢谢,如果觉得悬赏太少的话可以说,我再加。急。。
- 2、Java服务器端如何接收IOS远程推送传递来的devicetoken
- 3、Java服务器如何接收ios上传上来的图片,急急!!!
- 4、java socket服务器接收客户端信息问题
- 5、java,一台机器同时是客户端和服务器,服务器接收客户端信息并显示
Java服务器怎么接收手机上传过来的文件。求具体代码,谢谢,如果觉得悬赏太少的话可以说,我再加。急。。
android客户端代码:
public class MainActivity extends Activity
{
private TextView uploadInfo;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
uploadInfo = (TextView) findViewById(R.id.upload_info);
uploadFile();
}
public void uploadFile()
{
//服务器端地址
String url = "";
//手机端要上传的文件,首先要保存你手机上存在该文件
String filePath = Environment.getExternalStorageDirectory()
+ "/1/power.apk";
AsyncHttpClient httpClient = new AsyncHttpClient();
RequestParams param = new RequestParams();
try
{
param.put("file", new File(filePath));
param.put("content", "liucanwen");
httpClient.post(url, param, new AsyncHttpResponseHandler()
{
@Override
public void onStart()
{
super.onStart();
uploadInfo.setText("正在上传...");
}
@Override
public void onSuccess(String arg0)
{
super.onSuccess(arg0);
Log.i("ck", "success" + arg0);
if(arg0.equals("success"))
{
Toast.makeText(MainActivity.this, "上传成功!", 1000).show();
}
uploadInfo.setText(arg0);
}
@Override
public void onFailure(Throwable arg0, String arg1)
{
super.onFailure(arg0, arg1);
uploadInfo.setText("上传失败!");
}
});
} catch (FileNotFoundException e)
{
e.printStackTrace();
Toast.makeText(MainActivity.this, "上传文件不存在!", 1000).show();
}
}
}
服务器端代码:
public class UploadFileServlet extends HttpServlet
{
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
// 创建文件项目工厂对象
DiskFileItemFactory factory = new DiskFileItemFactory();
// 设置文件上传路径
String upload = this.getServletContext().getRealPath("/upload/");
// 获取系统默认的临时文件保存路径,该路径为Tomcat根目录下的temp文件夹
String temp = System.getProperty("java.io.tmpdir");
// 设置缓冲区大小为 5M
factory.setSizeThreshold(1024 * 1024 * 5);
// 设置临时文件夹为temp
factory.setRepository(new File(temp));
// 用工厂实例化上传组件,ServletFileUpload 用来解析文件上传请求
ServletFileUpload servletFileUpload = new ServletFileUpload(factory);
// 解析结果放在List中
try
{
ListFileItem list = servletFileUpload.parseRequest(request);
for (FileItem item : list)
{
String name = item.getFieldName();
InputStream is = item.getInputStream();
if (name.contains("content"))
{
System.out.println(inputStream2String(is));
} else if(name.contains("file"))
{
try
{
inputStream2File(is, upload + "\\" + item.getName());
} catch (Exception e)
{
e.printStackTrace();
}
}
}
out.write("success");
} catch (FileUploadException e)
{
e.printStackTrace();
out.write("failure");
}
out.flush();
out.close();
}
// 流转化成字符串
public static String inputStream2String(InputStream is) throws IOException
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int i = -1;
while ((i = is.read()) != -1)
{
baos.write(i);
}
return baos.toString();
}
// 流转化成文件
public static void inputStream2File(InputStream is, String savePath)
throws Exception
{
System.out.println("文件保存路径为:" + savePath);
File file = new File(savePath);
InputStream inputSteam = is;
BufferedInputStream fis = new BufferedInputStream(inputSteam);
FileOutputStream fos = new FileOutputStream(file);
int f;
while ((f = fis.read()) != -1)
{
fos.write(f);
}
fos.flush();
fos.close();
fis.close();
inputSteam.close();
}
}
Java服务器端如何接收IOS远程推送传递来的devicetoken
您好,(1)下载前面建立的cer文件和provisioning文件,双击,导入到xcode中,在build setting中code signing一栏里选择这两个文件的名称,这样就可以将支持push的app部署到真机中。
(2)处理推送消息
客户端对推送消息的处理分两种情况:
一. 在App没有运行的情况下,系统收到推送消息,用户点击推送消息,启动App。此时,不会执行前面提到的 didReceiveRemoteNotification函数,而是在App的applicationDidFinishLaunching函数中处理推送,通过以下代码可以获取推送消息中的数据: NSDictionary *userInfo =[launchOptionsobjectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
二 . 当APP处于前台时,系统收到推送消息,此时系统不会弹出消息提示,会直接触发application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo函数,推送数据在userInfo字典中。
当App处于后台时,如果系统收到推送消息,当用户点击推送消息时,会执行application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo函数,
此时AppDelegate中函数执行的顺序为:
applicationWillEnterForeground
application:didReceiveRemoteNotification
applicationDidBecomeActiveI
Java服务器如何接收ios上传上来的图片,急急!!!
只要开放出一个服务器的访问路径就可以了,不过我没用过spring mvc,如果用struts2的话就建个action,接收传过来的图片就可以了。
java socket服务器接收客户端信息问题
先把你的业务代码注释掉,直接打印接收到的数据看看,有没有可能是客户端两次的数据合并了,还有可能是业务代码太慢,导致第三次把第二次的给覆盖了,第四次的被第五次的给覆盖了。
java,一台机器同时是客户端和服务器,服务器接收客户端信息并显示
假设你有a、b两台计算机,那么a可以向b发送文件,b也可以向a发送文件。所以在实现的时候,你的软件既要实现服务器的功能,也要实现客户端的功能。即:你的软件既可以申请发送文件,也可以在别人向你发送文件时接收文件。实现也不难,只是你判断用户需要的功能,然后根据功能实现相应的操作就行了。
关于java服务器接收和java服务器接收多线程的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。
发布于:2022-12-17,除非注明,否则均为
原创文章,转载请注明出处。