简体   繁体   English

将String变量从Java传递到JSP

[英]Passing String variable from java to jsp

I am trying to pass a string variable from my java class as follow: 我试图从我的java类传递一个字符串变量,如下所示:

request.setAttribute("fdata",fileName); 

in order to send it to my jsp file as follow: 为了将其发送到我的jsp文件,如下所示:

var fd ="0";
fd=<%= (String) request.getAttribute("fdata").toString()%>;
document.getElementById("reed").value = fd;

the problem is that the 'fileName' which is a string variable in java is converted to integer for example if I pass this string : "5-9" the result that i see in 'reed' textbox is (-4) or if i pass "8-7" the result will be (1) and if I pass something else eg "5-8dfs" it doenst show anything. 问题是,例如,如果我传递以下字符串,则java中作为字符串变量的'fileName'会转换为整数:“ 5-9”我在'reed'文本框中看到的结果是(-4)或通过“ 8-7”,结果将是(1),如果我通过其他内容,例如“ 5-8dfs”,它确实会显示任何内容。 I think my jsp file sees the string variable as integer variables and mathematical operators instead of String variable itself, any hint or suggestions ?? 我认为我的jsp文件将字符串变量视为整数变量和数学运算符,而不是字符串变量本身,任何提示或建议?

Thanks very much. 非常感谢。

Your JavaScript string doesn't have quotes. 您的JavaScript字符串没有引号。 I think you want to do this instead: 我认为您想改为这样做:

fd="<%= (String) request.getAttribute("fdata").toString()%>";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM