Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5d88452

Browse files
author
Johnathan Ciqueira
committed
first commit
0 parents commit 5d88452

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+888
-0
lines changed

‎HTTP/httpServerEx1/.classpath

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
4+
<classpathentry kind="src" path="src"/>
5+
<classpathentry kind="output" path="bin"/>
6+
</classpath>

‎HTTP/httpServerEx1/.project

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>httpServerEx1</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
4+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5+
org.eclipse.jdt.core.compiler.compliance=1.8
6+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
8+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11+
org.eclipse.jdt.core.compiler.source=1.8
1.57 KB
Binary file not shown.
1.21 KB
Binary file not shown.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<html>
2+
<body>
3+
4+
<form action="http://localhost:8000/abc">
5+
Send GET request
6+
Name <input type="text" name="name" />
7+
<input type="submit" value="click" />
8+
</form>
9+
10+
<br/>
11+
12+
<form action="http://localhost:8000/abc" method="post">
13+
Send Post request
14+
Name <input type="text" name="name" />
15+
<input type="submit" value="click" />
16+
</form>
17+
18+
<br/>
19+
20+
<form action="http://localhost:8000/abc" method="post" enctype="multipart/form-data">
21+
Send multipart request
22+
Name <input type="text" name="name" />
23+
File <input type="file" name="attachment" />
24+
<input type="submit" value="click" />
25+
</form>
26+
27+
</body>
28+
</html>
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package defaultFail;
2+
3+
import java.io.InputStream;
4+
import java.io.OutputStream;
5+
import java.io.PrintWriter;
6+
import java.net.ServerSocket;
7+
import java.net.Socket;
8+
9+
class SocketUtils {
10+
11+
public static String getRequest(Socket sock) throws Exception {
12+
13+
StringBuilder requestString = new StringBuilder();
14+
15+
byte[] requestBytes = new byte[40000];
16+
17+
InputStream in = sock.getInputStream();
18+
int n = in.read(requestBytes);
19+
20+
String requestPart1 = null;
21+
22+
if (n != -1) {
23+
requestPart1 = new String(requestBytes, 0, n);
24+
requestString.append(requestPart1);
25+
}
26+
27+
if (requestPart1 != null && requestPart1.contains("multipart/form-data")) {
28+
n = in.read(requestBytes);
29+
if (n != -1) {
30+
requestString.append(new String(requestBytes, 0, n));
31+
}
32+
}
33+
34+
return requestString.toString();
35+
}
36+
}
37+
38+
public class Server {
39+
40+
public static void main(String[] args) throws Exception {
41+
42+
ServerSocket serSocket = new ServerSocket(8000);
43+
44+
while (true) {
45+
46+
System.out.println("\n\nWaiting for client...\n\n");
47+
48+
Socket sock = serSocket.accept();
49+
50+
String request = SocketUtils.getRequest(sock);
51+
52+
System.out.println("Obtained Request .... \n\n" + request);
53+
54+
OutputStream out = sock.getOutputStream();
55+
56+
PrintWriter pw = new PrintWriter(out);
57+
58+
pw.println("HTTP/1.0 200 OK");
59+
pw.println("Content-type: text/html");
60+
61+
pw.println();
62+
63+
pw.println("<html><body>Welcome</body></html>");
64+
65+
pw.close();
66+
67+
sock.close();
68+
}
69+
}
70+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<html>
2+
<body>
3+
4+
<form action="http://localhost:8000/abc">
5+
Send GET request
6+
Name <input type="text" name="name" />
7+
<input type="submit" value="click" />
8+
</form>
9+
10+
<br/>
11+
12+
<form action="http://localhost:8000/abc" method="post">
13+
Send Post request
14+
Name <input type="text" name="name" />
15+
<input type="submit" value="click" />
16+
</form>
17+
18+
<br/>
19+
20+
<form action="http://localhost:8000/abc" method="post" enctype="multipart/form-data">
21+
Send multipart request
22+
Name <input type="text" name="name" />
23+
File <input type="file" name="attachment" />
24+
<input type="submit" value="click" />
25+
</form>
26+
27+
</body>
28+
</html>

‎HTTP/httpServerEx2/.classpath

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
4+
<classpathentry kind="src" path="src"/>
5+
<classpathentry kind="output" path="bin"/>
6+
</classpath>

‎HTTP/httpServerEx2/.project

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>httpServerEx2</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /