troubleshooting Question

servlet - forward post to another server

Avatar of FTIISD
FTIISD asked on
JSP
2 Comments1 Solution540 ViewsLast Modified:
Hello,

I have the following servlet that is called from an html form using post:

package com.test.web;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class OrderSelect extends HttpServlet {
      public void doPost(HttpServletRequest request,
                                    HttpServletResponse response)
                                    throws IOException, ServletException {
            
            String sSize = request.getParameter("size");
            String sType = request.getParameter("types");
            String sProductInfo = request.getParameter("productinfo");
            String qty = request.getParameter("qty");

            double fPrice;            
            String sProduct;
            
            sProduct = "Type: " + sType + "  Size: " + sSize + "  Shirt: " + sProductInfo;
            
            if(sType == "Unisex")
            {
                  fPrice = 20.00;
            }else{
                  fPrice = 25.00;
            }
            
            if(sSize == "XX-Large + $3.50 USD" || sSize == "XXX-Large + $3.50 USD")
            {
                  fPrice += 3.50;
            }

            //request.setAttribute("price", fPrice.toString());
            request.setAttribute("product", sProduct);
            request.setAttribute("userid", "uid123");
            
            RequestDispatcher view = request.getRequestDispatcher("http://www.123site.com/cf/add.cfm");

            view.forward(request, response);
      }
}

Question 1:
I understand that the above code is meant to forward both the request and the response object to a jsp file, on my local server.  What i need to do (I believe) is post all of these variables to another server using the post method. (I am assuming this is the same as forwarding both the request and the response objects to a remote server.  This server is not using jsp, but just needs a request the same as if i was posting it through an html form.

Question 2:
Why can't I cast a double into a string using: request.setAttribute("price", fPrice.toString()); and how do i do it?

I am new to this so please be gentle.

Thanks for your help.
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros