tags:

views:

29

answers:

1

I am new to JSP and Servlets.

What i want to know is the best way to pass some customized message to client web pages.

For example suppose i have a web page say student.jsp which has a form,to register a new student to our online application.after successfully inserting all the fields of the form, user submits the form and data is submitted to our servlet for further processing.Now,Servlet validates it and add it to our database.so,now servlet should send a message indicating a successful insertion of data entered by end user to end user (In our case student.jsp).

So,i could i pass this type of message to any client web page.

I don't want to pass this message as URL query String.

is there ant other better and secure way to pass these type of messages ...

+2  A: 

use request.setAttribute("message", yourMessage) and then forward (request.getRequestDispatcher("targetPage.jsp").forward()) to the result page.

Then you can read the message in the target page via JSTL (<c:out value="${message}" />) or via request.getAttribute(..) (this one is not preferable - scriptlets should be avoided in jsp)

If you really need response.sendRedirect(..), then you can place the message in the session, and remove it after it is retrieved. For that you might have a custom tag, so that your jsp code doesn't look too 'ugly'.

Bozho
thanks for this good suggestion.but what if i use response.sendRedirect instead of request.getRequestDispacther.Can i use attribute methods with sendRedirect ?any Special benefit Using attribute methods ??Thank YouMihir Parekh
Mihir
redirecting makes another request, hence attributes are lost.
Bozho
thanks for your reply.but can you suggest a way to send message to client side while i am using response.sendRedirect ??
Mihir
place in session and then remove it from it.
Bozho