Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tomcatserver3.0 fix #102

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions tomcatServer3.0/.classpath

This file was deleted.

17 changes: 0 additions & 17 deletions tomcatServer3.0/.project

This file was deleted.

11 changes: 0 additions & 11 deletions tomcatServer3.0/.settings/org.eclipse.jdt.core.prefs

This file was deleted.

Binary file removed tomcatServer3.0/bin/com/hjy/GetPosyTest.class
Binary file not shown.
Binary file removed tomcatServer3.0/bin/com/hjy/request/Request.class
Binary file not shown.
Binary file removed tomcatServer3.0/bin/com/hjy/response/Response.class
Binary file not shown.
Binary file removed tomcatServer3.0/bin/com/hjy/server/Server.class
Binary file not shown.
Binary file not shown.
Binary file removed tomcatServer3.0/bin/com/hjy/util/GetParm.class
Binary file not shown.
52 changes: 52 additions & 0 deletions tomcatServer3.0/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.hjy</groupId>
<artifactId>tomcat-server</artifactId>
<version>3.0.0</version>
<packaging>jar</packaging>

<name>tomcat-server-3.0.0</name>
<url>http://www.example.com</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
<include>**/*.jpg</include>
<include>**/*.html</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>
</project>
107 changes: 0 additions & 107 deletions tomcatServer3.0/src/com/hjy/GetPosyTest.java

This file was deleted.

67 changes: 0 additions & 67 deletions tomcatServer3.0/src/com/hjy/server/Server.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.hjy.request;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.Map;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package com.hjy.response;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintStream;
import java.io.*;
import java.net.Socket;

import com.hjy.request.Request;
Expand All @@ -30,9 +26,9 @@ public Response(Socket client) {

public void forward() throws FileNotFoundException {
// 响应(把服务器上有的资源用流传给客户端)
FileInputStream fis = null;
InputStream fis = null;
try {
fis = new FileInputStream(new File(path));
fis = this.getClass().getClassLoader().getResourceAsStream(path);
ps.println("HTTP/1.1 200 OK");
ps.println();
byte[] buf = new byte[1024];
Expand Down Expand Up @@ -67,12 +63,12 @@ public void forward(String url) {
* url处理分3种情况 1.为空:返回默认资源 2.不空存在,返回该资源 3.不空不存在,返回错误信息
*/
if (url.equals("/")) {
path = "src/source/2.jpg";
path = "html/2.jpg";
} else {
path = "src/source" + url;
File file = new File(path);
if (!file.exists()) {
path = "src/source/error.html";
path = "html" + url;
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(path);
if (inputStream == null) {
path = "html/error.html";
}
}
try {
Expand Down
54 changes: 54 additions & 0 deletions tomcatServer3.0/src/main/java/com/hjy/server/Server.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.hjy.server;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ResourceBundle;

import com.hjy.serverThread.ServerThread;

public class Server {
@SuppressWarnings("unused")
private ServerSocket server;
private static int port;

static{
ResourceBundle serverConfig = ResourceBundle.getBundle("config/server");
port = Integer.parseInt(serverConfig.getString("port"));
}

//初始化,创建服务器
public void init() throws IOException {
server = new ServerSocket(port);
System.out.println("The server is running at "+ server.getLocalSocketAddress());
}
public void receive(){
try {
System.out.println("waiting client come to connect server!");
Socket client = server.accept();
System.out.println("client coming ...");
ServerThread thread = new ServerThread(client);
thread.start();
thread.join();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public Server() {
}

public static void main(String[] args) throws IOException {
//拿到server对象
Server server = new Server();
//创建服务器
server.init();
while(true){
server.receive();
}
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.hjy.serverThread;

import java.io.File;
import java.io.IOException;
import java.net.Socket;

import com.hjy.request.Request;
Expand Down
Binary file removed tomcatServer3.0/src/source/2.jpg
Binary file not shown.
10 changes: 0 additions & 10 deletions tomcatServer3.0/src/source/error.html

This file was deleted.

Loading