Solved

Strange problem with request.getParameter

Posted on 2009-07-15
6
422 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ForLoop Example 3 48
windows explorer path to command prompt 5 43
expectj telnet failing 5 35
Java: anonymous class 4 17
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

785 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