I have a JSP page (home page) in a Web App, which has different anchor tags (like home, video, pictures, profile etc) for navigation in a Web App.
For, anchor tags I am using JSTL tag (c:url)
The Process:
I am on home page and press a anchor tag (like profile).
Anchor tag, which uses c:url tag of JSTL redirects it to profile page.
The profile page gets displayed with user information
The code that I am using in JSP:
<a href="<c:url value="/profile.jsp" />" >Profile</a>
What I want?
When anchor tag (profile page) is pressed on the home page, a method should be called to fetch the user details from database and populate it in appropriate bean So that it can be accessed in that profile 开发者_如何学Pythonpage using Expression Language
Is the above question/or method right to do so? If no, then Which process is better?
So the method you describe is a good start. However, to do the database part it might be better to look at using a Servlet. So you create a Servlet class that implements the doGet() method.
You have to create a mapping for your servlet in the web.xml file, so assume that you map the url: /profile to the servlet that you create then the link will be:
<a href="<c:url value="/profile" />" >Profile</a>
In that method you interact with your database, populate your bean and save it in the request scope. Next, you forward to the jsp page that will display the bean data.
On the jsp page the bean will be available for you to display the data.
精彩评论