StringBuffer 将为每个方法调用附加路径
我通过在java文件中使用StringBuffer动态设置contextPath。这里,对于每个调用,路径都会根据调用次数附加到 StringBuffer 对象。我怎样才能正确运行下面的代码。
StringBuffer blankDeposit = new StringBuffer();
blankDeposit.setLength(0);
String rcp = request.getContextPath();
String create = "Create";
blankDeposit.append("<a href="+rcp+"/deposit/showBlankDepositSheet.do>"+create+"</a>"+"a blank Deposit Sheet.");
ActionHelper.formatInfoMessage(
mapping,
request,blankDeposit.toString());
这里 blankDeposit
应该有带有字符串的 contextPath(/myapp)。但我得到的是一个空格而不是这个。为此我该怎么办呢。
blankDeposit
正在按我运行的次数附加字符串。如果我调用五次,则上面的变量blankDeposit包含五倍的附加字符串。
i am setting contextPath dynamically by using StringBuffer in java file. Here for every call the path is appending to StringBuffer Object based on number of calls. How can i run below code properly.
StringBuffer blankDeposit = new StringBuffer();
blankDeposit.setLength(0);
String rcp = request.getContextPath();
String create = "Create";
blankDeposit.append("<a href="+rcp+"/deposit/showBlankDepositSheet.do>"+create+"</a>"+"a blank Deposit Sheet.");
ActionHelper.formatInfoMessage(
mapping,
request,blankDeposit.toString());
Here blankDeposit
should have the contextPath(/myapp)with the String. But i am getting a blank space instead of this. How can i do for this.
And the blankDeposit
is appending the string by number of times i run. if i call five times then the above variable blankDeposit containing five times the appended string.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这按预期工作。检查上下文路径。如果没问题,请检查
blankDeposit
上是否有其他代码块可用。输出:
This works as expected. Check the contextPath. if that's fine, check any other code block works on
blankDeposit
.Output:
我得到了答案。在这里,我将参数传递给函数,
但我没有使用blankDeposit.toString(),而是将此
字符串作为参数发送给formatInfoMessage方法。
此 rcp 变量设置到 Application.properties 文件。在那里它被设置为
i got the answer. Here i am passing parameter to the function
But instead of that blankDeposit.toString() i am taking as
then i am sending this string as an argument to formatInfoMessage method.
this rcp variable setting to Application.properties file. there it is set as