Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

2 Web Browser (35 points) Your program should have a text edit box at the top of

ID: 3603716 • Letter: 2

Question

2 Web Browser (35 points) Your program should have a text edit box at the top of the Write a very simple GUI web window for the user to type a URL. Provide a listener that activates when the user types something in and presses "Enter" browser. The HTTP specification is fairly simple. Create a Socket object from the URL's web address, connecting on port 80 (the default HTTP port). You will probably want to attach a PrintWriter and a BufferedReader to the Socket. Send the following lines of text, ending in both carriage return and newline characters (yes, HTTP follows Windows line-ending conventions, rather than Unix): GET HTTP/1.1 Host: In other words, if the user typed "http://cs.okstate.edu/students.html", your program should send these three lines to the Socket: GET /students.html HTTP/1.1rln Host: cs.okstate.edu rl

Explanation / Answer

package com.chegg.test;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/htmlResponse")
public class LoginServlet extends HttpServlet {

protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {

PrintWriter writer = response.getWriter();

// build HTML code
String htmlRespone = "<html>";
htmlRespone += "<h2>HTTp Header junk <br/>";   
htmlRespone += "serveral lines</h2>";   
htmlRespone += "</html>";

// return response
writer.println(htmlRespone);

}

}

<html>
<head>
<title></title>
</head>
<body>
<form action="/htmlResponse" method="post">
<input type="text" name="url" size="50"/>
<input type="submit" tabindex="-1"/>
</form>
</body>
</html>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote