Jsp代码从表中的一行获取。
<li><a href="otherpageJsp?idParam1=${value1}&idParam2=${value2}"
onclick="otherpageJsp"</a></li>
在模型和视图中
@RequestMapping(value = "otherpageJsp")
public ModelAndView goPage(@RequestParam String idParam1,String idParam2, Model model) {
ModelAndView mav = new ModelAndView("otherpageJsp");
mav.addObject("current", "otherpageJsp");
mav.addObject("value1", idParam1);
mav.addObject("value2", idParam2);
return mav
当onclick()
被调用时,我只得到value1,value2 = null。有人可以帮我解决吗?
答案 0 :(得分:1)
只需添加 document.getElementById("guess").onclick=function() {
if(document.getElementById("myNumber").value > 5) {
document.getElementById("myNumber").value = "";
alert("Please provide a number that is with in 0 to 5");
} else {
var gotit=false;
var guesses=1;
var x;
while(gotit==false) {
x=Math.random();
x=6*x;
x=Math.floor(x);
if(document.getElementById("myNumber").value==x) {
gotit=true;
} else {
guesses++;
}
}
alert("Got it! It was a " + x + ". It only took me " + guesses + " guesses!");
}
即可将参数值设置为方法参数。
<script language="javascript">
var timeout;
function open_webapp() {
window.location='https://oursite.com/path/to/destination';
}
function try_to_open_app() {
timeout = setTimeout('open_webapp()', 300);
}
</script>
<a onClick="javascript:try_to_open_app();" href="yourappurl:">App name</a>
答案 1 :(得分:0)
在URL查询字符串中发送参数时,最好使用QueryParam
。试试这个:
public ModelAndView goPage(@QueryParam("idParam1") String idParam1, @QueryParam("idParam2") String idParam2, Model model) {
答案 2 :(得分:0)
你可以试试这个
@RequestMapping(value = "otherpageJsp", method=RequestMethod.GET)
public ModelAndView goPage(@RequestParam("idParam1") String idParam1, @RequestParam("idParam2") String idParam2, Model model) {
ModelAndView mav = new ModelAndView("otherpageJsp");
mav.addObject("current", "otherpageJsp");
mav.addObject("value1", idParam1);
mav.addObject("value2", idParam2);
return mav
}
答案 3 :(得分:0)
对我有用。我将jst用于href
HTML
<c:url var="addNewDistribution" value="/credit/showFormforAddDistribution">
<c:param name="credit" value="${creditNumber}" />
<c:param name="work" value="${creditNumber}" />
</c:url>
<a href="${addNewDistribution}">add</a>
模型视图
@GetMapping("/showFormforAddDistribution")
public String showFormforAddDistribution(@RequestParam String credit,@RequestParam String work, Model theModel) {}