问题描述
我是JSP的初学者,需要一些帮助.我从我的第一个JSP页面中的这段代码开始了
I am a beginner in JSP and need some help. I started out with this bit of code inside one of my first JSP pages
<%
LoginService user = new LoginService();
%>
Hello <%=user.getUserID() %>!
工作正常.我正确导入了LoginService类,并且那段代码起作用了!但是现在我正在学习JSTL,并尝试将以上内容转换为JSTL标签.所以我右脚下车,但需要一些帮助.到目前为止,我有
And works just fine. I imported the LoginService class correctly and that bit of code works! But now I am learning JSTL and trying to convert the above to JSTL tags. So I got off on the right foot but need some help finishing. So far I have
<jsp:useBean id="user" class="org.test.LoginService"></jsp:useBean>
但是我在将最后一个Hello行转换为JSTL标签时遇到了麻烦!我不知道如何像在JSP标记中那样引用方法getUserID().我自己已经走了这么远,但需要一些帮助才能完成!任何回应将不胜感激!
But I'm having trouble converting that last Hello line into a JSTL tag! I can't figure out how to reference the method getUserID() like I did in the JSP tag. I've come this far on my own but need some help finishing up! Any response would be greatly appreciated!
推荐答案
您可以使用:
<jsp:getProperty name="user" property="userID" />
但最好使用:
${user.userID}
这篇关于将JSP转换为JSTL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!