Sobes.tech
Junior — Middle

Ma'lumotlarni ko'rsatish uchun mijozga HTML sahifa yuboradigan server ilovasini qanday amalga oshirish mumkin?

sobes.tech AI

AIdan javob

Java'da mijozga HTML sahifa yuboradigan server ilovasini amalga oshirish uchun servlets yoki Spring Boot kabi frameworklardan foydalanish mumkin.

Servlet bilan misol:

@WebServlet("/hello")
public class HelloServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        resp.setContentType("text/html;charset=UTF-8");
        PrintWriter out = resp.getWriter();
        out.println("<html><body><h1>Salom, mijoz!</h1></body></html>");
    }
}

Bu servlet /hello yo'liga GET so'rovi bo'lsa, oddiy HTML sahifa yuboradi. Murakkabroq ilovalarda, odatda, shablon motorlari (Thymeleaf, JSP) va frameworklar HTML bilan ishlashni osonlashtirish uchun ishlatiladi.