Saturday, July 2, 2011

JSP Servlet HTML Communication

When you are working with jsp & servlets you need to go from one page to another & that page may be a jsp, servlet, java page or html page. Well I know how I suffered from those basic stuff when I am at the basics. So to   make you feel better let me give some hints on those conversions.

  • HTML to Sevlet
< form action ="/newservlet" method ="post" />
Here the form action will be the page you need to go after a submit. Here the servlet page is newservlet.java.
  •  JSP to Servlet
<jsp:include page="/newservlet.java" Flush="true" />
This jsp:include will make a jsp page request to go to a servlet & do the logic within the request & return the values will be return to the jsp page again.
  • JSP to JSP
<jsp:forward page="/newjsp.jsp" />
The jsp:forward command will redirect the current page to another page (newjsp.jsp).
  • Servlet to JSP/HTML
String des = "/newjsp.jsp";
response.SendRedirect(response.encodedRedirect(des));

Another way.
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/testin.html");
Dispatcher.include(request,response);

So hope you find this post helpful for you to begin work. :)


1 comment:

  1. how to get current month from system & how to display the number of weeks in that month in jsp, servlets?

    ReplyDelete