Vienkāršs servlets

Last modified by superadmin on 2018-01-12 20:39

Vienkāršs servlets

Minimāls Javas servlets, kurš drukā 2 rindiņas ar HTML dokumentu, izskatās apmēram šādi: 

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class HelloServlet extends HttpServlet {
    public void doGet (HttpServletRequest request,
                       HttpServletResponse response) {
        try {
            PrintWriter out = response.getWriter();
            response.setContentType("text/html; charset=UTF-8");
            out.println("<h1>Sveicin\u0101ta, Java</h1>");
            out.close();
        }
        catch (Exception e) {
            out.println("<pre>");
            e.PrintStackTrace(out);
            out.println("</pre>");
        }
    }
}
Tags:
Created by Kalvis Apsītis on 2008-05-04 17:34
    
This wiki is licensed under a Creative Commons 2.0 license
XWiki Enterprise 6.4 - Documentation