Solved

Strange problem with request.getParameter

Posted on 2009-07-15
6
418 Views
Last Modified: 2013-11-11
Hi Experts,

I am facing a strange problem with getting values from URL.

So in my controller, I have two methods: getExcel and getChart.

getExcel renders a table in excel sheet and getChart renders a flash chart.

Both the methods have identical structure, except for the return statement.

Problem I am facing is with the variable liabilityCode in getExcel method.
String liabilityCode = request.getParameter("liabilityCode");

I am not able to fetch this value out of URL. where as the same liabilityCode is getting fetched perfectly fine in the method below it (getChart). The strange issue is, except for liabilityCode, I am able to fetch all other parameters. your insight on this would be highly helpful
package com.si.analytics.ui;
 

import java.util.Arrays;

import java.util.Collection;

import java.util.HashMap;

import java.util.List;

import java.util.Map;
 
 

import javax.servlet.http.HttpServletRequest;
 

import net.sf.json.JSONObject;
 

import org.apache.log4j.Logger;

import org.springframework.stereotype.Controller;

import org.springframework.ui.ModelMap;

import org.springframework.web.bind.ServletRequestUtils;

import org.springframework.web.bind.annotation.ModelAttribute;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;
 

import com.si.myworld.business.Chart;

import com.si.myworld.dao.ChartData;
 
 

@Controller

public class DetailChartController {
 

	private static final Logger log = Logger.getLogger(DetailChartController.class);

	

	@RequestMapping(value="/excel.html", method=RequestMethod.GET)

	   public String getExcel(HttpServletRequest request, ModelMap model) {

		String chartType = request.getParameter("chartType");

		String chartGroup = request.getParameter("chartGroup");

		String chartSubgroup = request.getParameter("chartSubgroup");

		String timeline = request.getParameter("timeline");

		String liabilityCode = request.getParameter("liabilityCode");
 

		int id = ServletRequestUtils.getIntParameter(request, "chartId", 0);

		String startDt = request.getParameter("startDt");

		String endDt = request.getParameter("endDt");

		

		Chart crt = new Chart();

		crt.setChartGroup(chartGroup);

		crt.setChartSubgroup(chartSubgroup);

		crt.setTimeline(timeline);

		crt.setChartType(chartType);

		crt.setLiabilityCode(liabilityCode);

				

		crt.setChartId(id);

		crt.setStartDt(startDt);

		crt.setEndDt(endDt);

			

		ChartData cd = new ChartData();

	    String chartXml = cd.getChartXml(crt);

	

		String chartDatasource = cd.fetchChartDatasourceName(crt.getChartSubgroup());		

		

		model.put("chartType", chartType);

		model.put("chartGroup", chartGroup);

		model.put("chartSubgroup", chartSubgroup);

		model.put("timeline", timeline);	

		model.put("liablityCode", liabilityCode);

		model.put("detailForm", crt);

	

	

		model.put("chartId", id);

		model.put("startDt", startDt);

		model.put("endDt", endDt);

		model.put("chartDatasource", chartDatasource);
 

			

		String detailRes = cd.getChartDetailDataNew(crt);

		model.put("detailData", detailRes);

		return "excelTable";

	}

		

	   	

	@RequestMapping(value="/chartDetail.html", method=RequestMethod.GET)

      public String getChart(HttpServletRequest request, ModelMap model) {

		String chartType = request.getParameter("chartType");

		String chartGroup = request.getParameter("chartGroup");

		String chartSubgroup = request.getParameter("chartSubgroup");

		String timeline = request.getParameter("timeline");

		String liabilityCode = request.getParameter("liabilityCode");
 

		int id = ServletRequestUtils.getIntParameter(request, "chartId", 0);

		String startDt = request.getParameter("startDt");

		String endDt = request.getParameter("endDt");

		

		Chart crt = new Chart();

		crt.setChartGroup(chartGroup);

		crt.setChartSubgroup(chartSubgroup);

		crt.setTimeline(timeline);

		crt.setChartType(chartType);

		crt.setLiabilityCode(liabilityCode);

				

		crt.setChartId(id);

		crt.setStartDt(startDt);

		crt.setEndDt(endDt);

	

		

		ChartData cd = new ChartData();

	    String chartXml = cd.getChartXml(crt);

				

		//added 7/2/09

		String chartDatasource = cd.fetchChartDatasourceName(crt.getChartSubgroup());		

		

		model.put("chartType", chartType);

		model.put("chartGroup", chartGroup);

		model.put("chartSubgroup", chartSubgroup);

		model.put("timeline", timeline);	

		model.put("liablityCode", liabilityCode);

		model.put("detailForm", crt);

			

		//pp on 7/2/09

		model.put("chartId", id);

		model.put("startDt", startDt);

		model.put("endDt", endDt);

		model.put("chartDatasource", chartDatasource);
 

			

		String detailRes = cd.getChartDetailDataNew(crt);

		model.put("detailData", detailRes);

		

		//breadcrumb

		String breadcrumb = crt.getChartGroup() + ">>" 	+ crt.getChartSubgroup();

		model.put("breadcrumb", breadcrumb);

		

    	return "TestDetail";

    }
 
 

	

	@RequestMapping(value="/chartDetail.html", method=RequestMethod.POST)

	public String setChartPosition(HttpServletRequest request) {				

		return("redirect:/index.html");

	}

	

		

	@ModelAttribute("chartGroups")

	public Collection<String> populateGroups() {

		return populateSubgroups().keySet();

	}
 

	@ModelAttribute("chartSubgroups")

	public JSONObject getSubgroups() {

		return JSONObject.fromObject(populateSubgroups());

	}
 

	    public Map<String, List<String>> populateSubgroups() {

		

		Map<String, List<String>> groups = new HashMap<String, List<String>>();

		groups.put("Payment", Arrays.asList("AUTOPAY", "TXT2PAY"));

		groups.put("Registration", Arrays.asList("REGISTRATION"));

		groups.put("UpgradeChanges", Arrays.asList("UPGRADE_CHANGE"));

		

		return groups;

	}

	    
 

	@ModelAttribute("chartTypes")

	public Collection<String> populateTypes() {

		return Arrays.asList("bar", "line");

	}
 

	@ModelAttribute("timelines")

	public Collection<String> populateTime() {

		return Arrays.asList("Daily", "Weekly", "Monthly", "Quarterly",

				"Annual");

	}

	

	@ModelAttribute("liabilityCodes")

	public Collection<String> populateCustomers() {

		return Arrays.asList("IRU", "CRU");

	}

	

	

}

Open in new window

0
Comment
Question by:aman0711
  • 3
  • 2
6 Comments
 
LVL 3

Accepted Solution

by:
SordSord earned 350 total points
ID: 24862012
In what way are you detecting it is not working? Just on the final output? Or is an exception being thrown somewhere?

Also, are you aware that in your model.put call you spell it "liablityCode" instead of "liabilityCode" (missing one i), although it is spelled the same in both functions, so perhaps it is intentional.
0
 
LVL 10

Author Comment

by:aman0711
ID: 24862623
Actually... I put some System.out statements in both the methods... getChart method prints everything including liability Code... getExcel method prints everything other than liability Code
0
 
LVL 3

Expert Comment

by:SordSord
ID: 24862933
My next step would be to use getParameterMap() and dump out all the names and values.

It may also be useful to know how you are making the request. Are you pasting in a link to your browser, or it is being generated programatically?
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 10

Author Comment

by:aman0711
ID: 24862954
The flow is like this

A.jsp   -->  B.jsp  --> Excel

So B.jsp is getting URL from A.jsp
0
 
LVL 3

Expert Comment

by:SordSord
ID: 24863137
Is there any chance that when A.jsp follows the excel path, it produces a slightly different request URL?

If possible, I think I'd try manually posting the request to B.jsp (using my browser), so I could verify that the problem is with B.jsp (and not with A.jsp).
0
 
LVL 92

Assisted Solution

by:objects
objects earned 150 total points
ID: 24865367
>                 model.put("liablityCode", liabilityCode);

its spelt wrong here as SordSord mentioned earlier
so the libilityCode will not be added to the model, and thus won't be included in the link to /excel.html
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now