StringBuffer 将为每个方法调用附加路径

发布于 2024-12-27 18:57:31 字数 771 浏览 2 评论 0原文

我通过在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

剧终人散尽 2025-01-03 18:57:31

这按预期工作。检查上下文路径。如果没问题,请检查 blankDeposit 上是否有其他代码块可用。

StringBuffer blankDeposit = new StringBuffer();
blankDeposit.setLength(0);
String rcp = "/myapp";
String create = "Create";
blankDeposit.append("<a href="+rcp+"/deposit/showBlankDepositSheet.do>"+create+"</a>"+"a blank Deposit Sheet.");
System.out.println(blankDeposit.toString());

输出:

<a href=/myapp/deposit/showBlankDepositSheet.do>Create</a>a blank Deposit Sheet.

This works as expected. Check the contextPath. if that's fine, check any other code block works on blankDeposit.

StringBuffer blankDeposit = new StringBuffer();
blankDeposit.setLength(0);
String rcp = "/myapp";
String create = "Create";
blankDeposit.append("<a href="+rcp+"/deposit/showBlankDepositSheet.do>"+create+"</a>"+"a blank Deposit Sheet.");
System.out.println(blankDeposit.toString());

Output:

<a href=/myapp/deposit/showBlankDepositSheet.do>Create</a>a blank Deposit Sheet.
赤濁 2025-01-03 18:57:31

我得到了答案。在这里,我将参数传递给函数,

ActionHelper.formatInfoMessage(mapping, request,blankDeposit.toString()); 

但我没有使用blankDeposit.toString(),而是将此

String rcp = request.getContextPath();

字符串作为参数发送给formatInfoMessage方法。

ActionHelper.formatInfoMessage(mapping,request,"create.a.blank.deposit.sheet",rcp);

此 rcp 变量设置到 Application.properties 文件。在那里它被设置为

info.create.deposit.sheet=<a href="{0}/deposit/showBlankSheet.do">Create</a> a blank Sheet.

i got the answer. Here i am passing parameter to the function

ActionHelper.formatInfoMessage(mapping, request,blankDeposit.toString()); 

But instead of that blankDeposit.toString() i am taking as

String rcp = request.getContextPath();

then i am sending this string as an argument to formatInfoMessage method.

ActionHelper.formatInfoMessage(mapping,request,"create.a.blank.deposit.sheet",rcp);

this rcp variable setting to Application.properties file. there it is set as

info.create.deposit.sheet=<a href="{0}/deposit/showBlankSheet.do">Create</a> a blank Sheet.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文