Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pk.wieik.ti;
- import java.io.*;
- import jakarta.servlet.ServletContext;
- import jakarta.servlet.http.*;
- import jakarta.servlet.annotation.*;
- import pk.wieik.ti.model.JBuzytkownik;
- import pk.wieik.ti.model.Narzedzia;
- @WebServlet(name = "helloServlet", value = "/hello-servlet")
- public class HelloServlet extends HttpServlet {
- private String message;
- public void init() {
- message = "Hello World!";
- }
- public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
- response.setContentType("text/html");
- response.setCharacterEncoding("UTF-8");
- ServletContext context = getServletContext();
- PrintWriter out = response.getWriter();
- HttpSession sesja = request.getSession();
- String atrybut1 = (String) sesja.getAttribute("atrybut1");
- Integer atrybut2 = (Integer) sesja.getAttribute("atrybut2");
- if (atrybut1 == null)
- atrybut1 = "";
- if (atrybut2 == null)
- atrybut2 = 0;
- JBuzytkownik uzytkownik = (JBuzytkownik) sesja.getAttribute("uzytkownik");
- if (uzytkownik == null) {
- uzytkownik = new JBuzytkownik();
- sesja.setAttribute("uzytkownik", uzytkownik);
- }
- String strona = request.getParameter("strona");
- if (uzytkownik.getUprawnienia()>0)
- strona = Narzedzia.parsujStrone(strona, "glowna;kwadratowe;trzecia;ustawienia");
- else
- strona = Narzedzia.parsujStrone(strona, "glowna;kwadratowe;trzecia");
- String szablon = Narzedzia.pobierzSzablon("index.html", context);
- szablon = Narzedzia.uzupelnij(szablon, "NAGLOWEK", "naglowek.html", context);
- szablon = Narzedzia.uzupelnij(szablon, "MENU", "menu.html", context);
- String authHtml = "";
- if (uzytkownik.getUprawnienia() > 0) {
- authHtml = "<li><a href='?strona=ustawienia'>Ustawienia</a></li>" +
- "</ul><div style='background:#e9e9e9;padding:8px;margin-top:6px;'>" +
- "Jesteś zalogowany jako <strong>" + uzytkownik.getLogin() + "</strong> " +
- "<form method='post' action='JB' style='display:inline;'>" +
- "<input type='hidden' name='akcja' value='logout'/>" +
- "<input type='submit' value='Wyloguj'/>" +
- "</form></div>";
- } else {
- authHtml = "</ul><div style='background:#e9e9e9;padding:8px;margin-top:6px;'>" +
- "<form method='post' action='JB'>" +
- "<label>Login:<br/><input type='text' name='login'/></label><br/>" +
- "<label>Hasło:<br/><input type='password' name='haslo'/></label><br/>" +
- "<input type='hidden' name='akcja' value='login'/>" +
- "<input type='submit' value='Zaloguj'/>" +
- "</form></div>";
- }
- szablon = szablon.replace("[[AUTH]]", authHtml);
- szablon = Narzedzia.uzupelnij(szablon, "TRESC", "tresc.html", context);
- szablon = Narzedzia.uzupelnij(szablon, "STOPKA", "stopka.html", context);
- out.println(szablon);
- out.close();
- }
- public void destroy() {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment