-1

I am having web application where I have to send messages from one servlet to another and servlet to JSP. The default way to do that would be using RequestDispatcher and calling request.setAttribute("name",message);.

True, but I have some places where I have to use response.sendRedirect() in order to stop multiple submitting of forms on manual refersh.

The most known way to send messages in this case would be using Session and adding the message to the session.

However using session for passing messages is not a good idea, because the message is actually an item which should be belong to the request scope. So, any other good way of passing it to servlet and Jsp? In JSP I am using JSTL so please tell me how to get the passed object using that as well.

PeakGen
  • 21,894
  • 86
  • 261
  • 463

2 Answers2

1

Possibly you could use cookies, Query String, url re-writing, etc.

Query String:

String path = 'next.jsp';
path += '?name=' + messge;

You can use:

response.sendRedirect(path);

OR

request.getRequestDispatcher(path).forward(request, response);

On the landing page you can get the message just by request.getParameter("name")

0

If you are using any framework like Struts 2 you could store it to application scope https://struts.apache.org/docs/accessing-application-session-request-objects.html

If you are using a simply Servlet and session is not space free enought to store what you want, you could consider storing it to file disk or DB and then read it from any Servlet you want.

This question is related if it's your case: What is the best place to store a configuration file in a Java web application (WAR)?

Community
  • 1
  • 1
exoddus
  • 2,230
  • 17
  • 27