English 中文(简体)
我如何利用JAVA向服务器提供客户方回答(问题)?
原标题:How can I Submit client side answers (to a question) to the server using JAVA?

我如何利用JAVA向服务器提供用户对计算机用户的回答(对多个选择问题)

  1. I have a centralized server and about 1000 client systems.
  2. In these 1000 systems students take multiple choice quiz at at time (in some 2 hrs time).
  3. Now i ve to send all these answers of these questions to the server in an asynchronous threaded queue when the student answer each question (all 1000 students)
  4. Also client have to wait if the server connection is a failure, in this case students should be able to continue taking quiz/exam. When I get the connection these answers in queue should be submitted to the server system.

我如何解决这一问题? 请就此建议/帮助我。

问题回答

首先,服务器必须在某些港口听取某些要求。 最为直截了当的选择是一位网络服务器,负责听取80港的吉大港山区的请求。 您可使用Apache Tomcat ,作为网络服务器和Java servletcontainer for this,并创设一个Java Servlet,其中聆听了某些

然后,在您的客户申请中,您可使用 rel=“nofollow noreferer”>java.net.URLConnection ,向Serlet公司提出吉里尔港港山区开发协会的请求。 您可以利用请求参数向Serlet提供信息。 E.g.

String param1 = URLEncoder.encode("param1", "UTF-8");
String param2 = URLEncoder.encode("param2", "UTF-8");
String query = String.format("param1=%s&param2=%s", param1, param2);
String servleturl = "http://example.com/context/servlet";

// To fire GET request, do so:
URLConnection connection = new URL(servleturl + "?" + query).openConnection;
InputStream response = connection.getInputStream();

// Or, to fire POST request, do so:
URLConnection connection = new URL(servleturl).openConnection;
connection.setDoOutput(true);
PrintWriter writer = new PrintWriter(new OutputStreamWriter(connection.getOutputStream(), "UTF-8"));
writer.write(query.getBytes("UTF-8"));
writer.close();
InputStream response = connection.getInputStream();

在《服务手册》中,为了从<代码>GET的要求中收集参数,执行doGet(如下:

String param1 = request.getParameter("param1");
String param2 = request.getParameter("param2");

希望这一帮助。

如果你记得贾瓦曾阻断I/O(java.net.Socketjava.net.ServerSocket)和通过t渠道拆开I/O(java.nio.channel.Shannel)的话,这取决于你想要使用哪一种联系。

在阻挡I/O做法的过程中,每个客户都有自己的生产者/消费者操作。

  • a thread that consumes answers that are queued locally and tries to dispatch them to the server
  • the GUI that cares about placing items in the answer s queue

每当您的消费者面能够向服务器发出答案时,就将其从点上删除。

在服务器上,你可以共同处理答案:

  • you have a thread that processes answers received from all clients (you can accumulate them in a buffer) and it puts itself in wait when the buffer is empty.
  • every connection from a client has it s own thread that receives answers and places them in the process queue.

这种做法是安全的,但具有很大的份量。 你们可以想到,在答复时就开一个链接,将其送至服务器,然后关闭。

否则,你就可以简单地利用UDP(实际上更能解决这类问题),但是,如果你的服务器收到答复,你将不得不考虑向客户发回确认。

例如:

  • student gives an answer: the answer is added to the client buffer
  • client thread tries to send its buffer over UDP
  • whenever a client receives an acknowledge for an answers it removes it from the buffer
  • it tries periodically to send still unacknowledged answers

在服务器方面:

  • whenever it receives an answer datagram from a client accumulate it on the process buffer
  • you have a thread that processes all the answers on the buffer
  • the server will send back an ackknowledge to the client to warn that answer has been received

但是,这仍然不能确定,因为光线上可能错失ack。

在任何情况下,均可使用<条码>。 反对输入Stream和ObjectOutputStream在客户和服务器之间直接通过物体。 因此,你可以想像一个cap化物体。

class Answer
{
   int studentId;
   int questionId;
   int answer;
}




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签