i am running a simple web server in java that is running on port 8080 on my machine , the server do receive request that come from browsers (when i write this URL (localhost:8080) ) however i wanted to receive request that come from this html page
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<form method="post" action="192.168.1.1:8080">
<input type="text" name ="txt">
<input type="submit" name="sub">
</form>
</body>
</html>
and the result was The webpage cannot be displayed
and my second try was this
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<form method="post" action="server.java">
<input type="text" name ="txt">
<input type="submit" name="sub">
</form>
</body>
</html>
and after i clicked the submit button it opened the download dialog (download server.java).
however i managed to initiate a request on my own in java
Socket socket = new Socket("localhost",8080);
String request = "get / http/1.1";
OutputStream os = socket.getOutputStream();
os.write(request.getBytes());
os.flush();
os.close();
and my server received that request with no problems , i am not sure what am I missing here and what is that layer that initiate a correct request to a php website for example.
Java is not a scripting language and does not work like php or perl. In your server you should map request URI to handling code (eg in web.xml). In your <form action="..."> you should provide an URI which your server will handle.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.