Hi all,

I was hoping somebody might be able to help me out w/ a pretty basic question. I'm creating a web app and trying to use the MVC pattern where I have a controller servlet that intercepts requests, does some work (like say reading from a database), possibly setting some application/session/request/page scope objects then forwards the request on to a JSP page that renders the info.

So far I've think I've got an ok handle how that's done (though I think I may be overusing and/or misusing the requestScope object to get things to the JSP page, but that's a different story).

Anyway, my question is: what about pages where it's not a 'request'? That is, it's not an html <form> being submitted. E.g imagine I have a page with a link that says 'Display Employees' and when the user clicks on this link, I want my app to query the database for all the employees and display them in a table. The issue I have is that this is just a 'link' not a <form> being submitted, so my controller servlet never even gets involved. How can I route this page to my controller servlet so that it can go out to query the database, etc. Is there a standard pattern for handling this scenario?

Anyway, hope that made sense. Sorry so basic. Just starting out w/ this.

thanks,

Bill

Recommended Answers

All 2 Replies

When you have a form with a servlet you have sth like that:

<form action="someServlet">
  ... data to be sent
</form>

For a link:

<%
String name = "a";
String pass = "a";
%>

<a href="someServlet?[B]name[/B]=<%=name%>&[B]password[/B]=<%=pass%>">
  Click Me!
</a>

Instead of <%=name%> you can have whatever you want:

<a href="someServlet?[B]name[/B]=1111&[B]password[/B]=2222">
  Click Me!
</a>

Or you can have more:
"someServlet?req1=111&req=2&req3=3&req4=4"

And at the servlet get them like this:

request.getParameter("[B]name[/B]");
request.getParameter("[B]password[/B]");

Thanks! I feel kind of stupid. That should have occurred to me. I'll have to rethink the way I've done some things already but I think I see how I can make it work like that.

regards,

Bill

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.