Solved

Strange problem with request.getParameter

Posted on 2009-07-15
6
423 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
custom annotations 9 42
map related example 6 55
jdbc error in jsp application 20 64
Detect Closed Loops (circles, figure-8s, etc) in PNG Images 6 58
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…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …

828 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