jsp静态导入
我创建了一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需使用EL。请求参数可通过
${param.name}
获取。您只需要考虑 XSS 即可。使用 JSTL
fn:escapeXml
为此:不要使用scriptlet(那些
<% %>
的东西)。它们被认为是不好的做法。ToDo.currentUser
是一个静态字段,这听起来也不太好。它的值将在 Web 应用程序中的所有请求/会话之间共享。不同的访问者将看到相同的值,任何修改都会反映给所有访问者。这就是你想要的吗?Just use EL. The request parameters are available by
${param.name}
.You only need to take XSS into account as well. Use JSTL
fn:escapeXml
for this: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?