I am trying to use websockets in an already running servlet. My problem is that I used the "writer" class to send HTML to broswer, but I cannot find a similar class for WebSockets.
My servlet looks like this:
@WebServlet("/TestServlet") public class TestServlet extends HttpServlet { private List<ISort> sortierListe = new ArrayList<ISort>(); private File file1; private PrintWriter writer2; private boolean sortFinished; boolean bSubmitForFilenamePressedCopy; BufferedReader in; // private String sEingabe; private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public TestServlet() { super(); this.initSortierverfahren(); } private void initSortierverfahren() { sortierListe.add(new BubbleSort()); sortierListe.add(new QuickSort()); } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse * response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { [...] PrintWriter writer = response.getWriter(); writer2 = writer; writer.println("<html>"); writer.println("<head><title>Text Sortieren!</title>"); writer.println("</head>"); writer.println("<body marginwidth='40' leftmargin='40' bgcolor='#E5E5E5'>"); writer.println("<table bgcolor='#FFFFFF' height='100%' width='57%' border='0' cellpadding=10>"); writer.println("<tr height='10%'>"); writer.println(" [...]
The code is too long to publish everything, but Servlet basically creates a form where I can enter the path to the TXT file. Then the txt file will be sorted using either bubblesort or quicksort.
My question is: how can I use this code in a WebSocket without rewriting everything in javascript? Just some basic help to get you started will help me a lot. Thanks in advance.
source share