Přidat otázku mezi oblíbenéZasílat nové odpovědi e-mailemVyřešeno Ajax ve springu - nefunguje mi hello world

Jen tak pro info, když mluvíš že spring nemá servlety, ve škole nás učili že springovskej servlet vypadá:

public abstract class AbstractServlet extends HttpServlet {

    private static final String MESSAGE_HEADER_ATTRIBUTE = "messageheader";
    private static final String MESSAGE_ATTRIBUTE = "message";

    protected AutowireCapableBeanFactory ctx;
    protected String jspFullPath;

    abstract void initJspFullPath();

    public AbstractServlet() {
        initJspFullPath();
    }

    @Override
    public void init(ServletConfig config) throws ServletException {
        super.init(config);
        WebApplicationContext context = WebApplicationContextUtils
                .getWebApplicationContext(getServletContext());
        ctx = context.getAutowireCapableBeanFactory();
        ctx.autowireBean(this);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.getRequestDispatcher(jspFullPath).forward(req,  resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        dispatchMessage("Acces denied", "Here, you should not be.", req, resp);
    }

    protected void dispatchMessage(String messageheader, String message, HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setAttribute(MESSAGE_HEADER_ATTRIBUTE, messageheader);
        req.setAttribute(MESSAGE_ATTRIBUTE, message);
        req.getRequestDispatcher("/WEB-INF/pages/message.j sp").forward(req, resp);
    }
}
A od něj dědí:

@WebServlet("/home")
public class UnloginHome extends AbstractServlet {

    @Override
    void initJspFullPath() {
        jspFullPath = "/WEB-INF/pages/unlogin/home.jsp";
    }
}
To není springovský servlet? (CONTROLER - jak říkáš?)

Edit full zdrojáky: https://github.com/danekja/pia-labs/tree/master/ex ample-app-spring

Reakce na odpověď

1 Zadajte svou přezdívku:
2 Napište svou odpověď:
3 Pokud chcete dostat ban, zadejte libovolný text:

Zpět do poradny