jsp静态导入

发布于 2024-08-30 01:01:28 字数 958 浏览 1 评论 0原文

我创建了一个 Spring Roo 项目。一切看起来都很好。现在我想向我的 index.jspx 添加一个带有文本输入和按钮的表单。此表单将更改我的 ToDo 类中的静态字段 currentUser。所以我添加:

<form>
  <%@ page import="static com.mypack.domain.ToDo.*" %>
   <label for="_username_id">My name is:</label>
    <% currentUser = request.getParameter("username"); %>
             <input type="text"  id="username" name="username" maxlength="30" path="username" size="0" value="<%= currentUser %>"/>
             <input type="submit"/>
</form>

在中间的某个地方。现在它不起作用:

This page contains the following errors:

error on line 6 at column 20: StartTag: invalid element name
Below is a rendering of the page up to the first error.

function readCookie(name) { var nameEQ = name + '='; var ca = document.cookie.split(';'); for(var i=0;i

如果我评论上面的行,它就可以正常工作。怎么了?有没有办法从jsp页面向类的静态字段写入值?我该如何解决这个问题?

I've created a Spring Roo project. Everything looks fine. Now I want to add a form with a text input and a button to my index.jspx. This form will change a static field currentUser in my ToDo class. So I'm adding:

<form>
  <%@ page import="static com.mypack.domain.ToDo.*" %>
   <label for="_username_id">My name is:</label>
    <% currentUser = request.getParameter("username"); %>
             <input type="text"  id="username" name="username" maxlength="30" path="username" size="0" value="<%= currentUser %>"/>
             <input type="submit"/>
</form>

somewhere in the middle of it. And now it won't work:

This page contains the following errors:

error on line 6 at column 20: StartTag: invalid element name
Below is a rendering of the page up to the first error.

function readCookie(name) { var nameEQ = name + '='; var ca = document.cookie.split(';'); for(var i=0;i

If I comment the lines above, it works just fine. What is wrong? Is there a way to write a value to a static field of a class from a jsp page? How do I work around this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

七分※倦醒 2024-09-06 01:01:28

只需使用EL。请求参数可通过 ${param.name} 获取。

<input type="text" name="username" value="${param.username}" />

您只需要考虑 XSS 即可。使用 JSTL fn:escapeXml 为此:

<input type="text" name="username" value="${fn:escapeXml(param.username)}" />

不要使用scriptlet(那些<% %> 的东西)。它们被认为是不好的做法

ToDo.currentUser 是一个静态字段,这听起来也不太好。它的值将在 Web 应用程序中的所有请求/会话之间共享。不同的访问者将看到相同的值,任何修改都会反映给所有访问者。这就是你想要的吗?

Just use EL. The request parameters are available by ${param.name}.

<input type="text" name="username" value="${param.username}" />

You only need to take XSS into account as well. Use JSTL fn:escapeXml for this:

<input type="text" name="username" value="${fn:escapeXml(param.username)}" />

Don't use scriptlets (those <% %> things). They are considered bad practice.

That the ToDo.currentUser is a static field also doesn't sound good. Its value would be shared among all requests/sessions in the webapplication. Different visitors will see the same value and any modifications will be reflected to all visitors. Is that what you want?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文