我一直在尝试编写一个简单的Web服务器的开头,但似乎无法获得发送的响应.我已经尝试了可以想象的每种类型的输出流,但似乎没有任何效果.我不知所措.这是我正在使用的两个类,抱歉一些无关的代码:
package edu.xsi.webserver;
import java.io.IOException;
import java.net.ServerSocket;
public class WebServer {
int port;
ServerSocket server;
public WebServer(int port) throws IOException{
this.port = port;
this.server = new ServerSocket(port);
Thread t = new Thread(new ServerExec());
t.start();
}
public class ServerExec implements Runnable {
public void run(){
int i = 0;
while (true) {
try {
new WebSession(server.accept(), i++);
System.out.println("Should print before session");
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public static void main(String[] args) {
try {
WebServer webServer …Run Code Online (Sandbox Code Playgroud) 我正在为课堂写第一个php页面.页面应该从表单中获取输入并输出.起初我尝试使用下面的$ content变量来存储一个html块,它可以输出表单或输出.我把它放在id ="content"div中,取决于是否设置了表单元素.无论如何,我离开了这个,因为我无法正确使用_SERVER ['PHP_SELF'] varialbe.我现在放弃这个,但现在遇到了类似的问题.这是我的代码到目前为止:
<?php
if (!empty($_POST['first-name']) && !empty($_POST['last-name'])
&& !empty($_POST['age']))
{
$fname = $_POST['first-name'];
$lname = $_POST['last-name'];
$age = $_POST['age'];
$content = '<h1>About You</h1>
<h4>First Name:</h4>
<p><?php echo $fname; ?></p>
<h4>Last Name:</h4>
<p><?php echo $lname; ?></p>
<h4>Age:</h4>
<p><?php echo $age; ?></p>';
}
else
{
$content = '';
}
//get the first name, last name and age from the form
?>
<html lang="en">
<head>
<title>Personal Info Results</title>
<link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>
<div class="content">
<h1>My Form</h1>
<form action="<?php …Run Code Online (Sandbox Code Playgroud)