开发者

How to call a method which populates bean, When I press a anchor tag with help of c:url

开发者 https://www.devze.com 2023-03-03 19:00 出处:网络
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.

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:

  1. I am on home page and press a anchor tag (like profile).

  2. Anchor tag, which uses c:url tag of JSTL redirects it to profile page.

  3. 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?

  1. 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

  2. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消