如何处理http GET请求整数参数?

时间:2019-02-12 13:23:58

标签: java html http jsp get

我正在尝试将两个值相乘,这是我从上一页获得的参数。我知道我可以使用以下方法分别显示它们:

<p> val1: <%= request.getParameter( "val1" ) %> </p>

<p> val2: <%= request.getParameter( "val2" ) %> </p>

但是,当执行乘法运算以求出这两个值的乘积时,下面尝试的尝试不起作用,所以我知道这种方法不正确

<p>product: (<%= request.getParameter( "val1" ) %> * <%= request.getParameter( "val2" ) %>)</p>

2 个答案:

答案 0 :(得分:1)

根据收到的错误,似乎您正在使用Java,因此您应该以这种方式转换整数:

<p>product: (<%= Integer.parseInt(request.getParameter("val1")) * Integer.parseInt(request.getParameter("val2")) %>)</p>

答案 1 :(得分:0)

假设您使用的这些符号用于ASPX页面,则答案将强制转换为 int

 public DisplayForm()
    {
        InitializeComponent(); 
        chart1.Series.Clear();
        var series = chart1.Series.Add("Series1");
        series.XValueMember = "Year";
        series.YValueMembers = "TotalIncome";
        ShowSoldProduct(); 
    }

  private void ShowSoldProduct()
    {
        using (HotelEntities db = new HotelEntities())
        {
            try
            {
                var result = (from pr in db.Transactions
                              select pr).ToArray();

                chart1.DataSource = result
                    .GroupBy(x => x.TransactionDate.Value.Year)
                    .Select(g => new
                    {
                        Year = g.Key,

                        TotalIncome = g.Sum(y => y.TotalPrice)
                    })
                    .ToArray();

                chart1.DataSource = result;
                chart1.DataBind();
                chart1.Show();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }


        }
    }