Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Multiple redirect to the same server  RSS feed

 
Anand Na
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I require to build an interface to an SMS gateway. The way the Gateway server accepts phone numbers is through a URL. Typically a URL would look like http://xyz.abc/request?user=aaa&pass=123&number=9800000001&Text= ..
However the Gateway will not accept multiple phone numbers to fowrward the same message. Hence I need to make multiple submits with just the phone number parameter varied.
I am collecting a comma separated string from a form and separating the input string using a String.split(","). Then I tried using a for loop to do a response.sendRedirect(URL info) with the one parameter varied.

However the Servlet is throwing an Exception and not allowing me to do such multiple submits. Is there any way I can accomplish this?? I tried doing a forward and a sendRedirect. Both get the same harsh treatment at the hands of the Servlet. Here's a code snippet

public void procSendMessage(SMS_Zni SMS, HttpServletRequest request, HttpServletResponse response, String strNumbers)
throws ServletException
{
String[] ArrString = strNumbers.split(",");

for (int iCounter = 0; iCounter< ArrString.length; iCounter++)
{
SMS.setText("userid=" + User + "&" +
"pwd=" + Password + "&" +
"senderid=" + FROM + "&" +
"sendto=" + ArrString[iCounter] + "&" +
"messageid=" + strMessage);
try
{
RequestDispatcher dispatcher = request.getRequestDispatcher(TO + SMS.getText());
dispatcher.forward(request,response);
***********************************OR*******************************
response.sendRedirect(TO + SMS.getText());
}
catch(IOException io)
{

}
 
Sunny Kumar
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suggest(an alternate) that instead of taking comma seperated numbers and going with the String.split() option, you can make multiple texboxes with name such as num1,num2,num3..etc. Or you can ask the user how many nos. will be entered so that you can accordingly generate that much no. of input field.
When this form is posted you can retreive the individual parameteres easily and form a new URL.
In this one can limit the numbers,apart from that client side validation can be used to check if the numbers are correct.
 
jiju ka
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

URL url = new URL(address);
String content = (String) url.getContent();


I don't know whether the above will fit your solution.

You want to generate multiple forwards to a single request. A single request seems to be originating from a browser. The request need to be parsed, multiplied and redispatched to another resource. I will assume you are trying to multiply and forward the request to another server. Server 1 should accept a 'post'ed request, parse the phone numbers out and create multiple requests to server 2.

The current approach will not work because "forward should be called before the response has been committed to the client (before response body output has been flushed). If the response already has been committed, this method throws an IllegalStateException. Uncommitted output in the response buffer is automatically cleared before the forward."

"If the response has already been committed, sendRedirect method throws an IllegalStateException. After using this method, the response should be considered to be committed and should not be written to."

Does the browser which initiates the request to server 1 expects anything from server 2 in the response?

Does the request to server2 can be fulfilled with just a 'get' operation?

Depending upon these, you may use the URL. If the answers are 'nothing' and 'yes', you can certainly use URL.

[ November 14, 2005: Message edited by: jiju ka ]
[ November 14, 2005: Message edited by: jiju ka ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!