问题
Want to generate page events(
pageload()
) in jsp is that possible?How to check weather a page is reloaded? In asp.net there is method name
isPostBack()
to check weather the page is request or reload is there anything in jsp?How to get start with struts and hibernate?
回答1:
To check for a page reload you could use 'onBodyload' and 'onBodyUnload' events in body tag of your HTML code.
For struts and hibernate check out onlojne documentation available. Good material to start with.
回答2:
You need to realize that JSP is just a view technology like as Classic ASP. JSP and Classic ASP are not a MVC framework like ASP.NET-MVC which offers the Page#IsPostback() method. The real Java counterpart of ASP.NET-MVC is JSF which offers the FacesContext#isPostback() method.
In plain vanilla JSP it's just as simple as implementing the method yourself:
public static boolean isPostback(HttpServletRequest request) {
return request.getMethod().equals("POST");
}
The point of a MVC framework is that it saves you from all the boilerplate code like that. If you want a Java counterpart of ASP.NET-MVC, then have a look at JSF (component based) or Spring MVC (request based). Struts and Hibernate are aged. Instead of Hibernate, have a look at JPA. Infact, have a look at the entire Java EE 6 API.
See also:
- What is the difference between JSF, JSP and Servlets?
- What is the Java alternative to ASP.NET and PHP?
来源:https://stackoverflow.com/questions/4688190/how-to-generate-events-in-jsp-pages