I'm using a Webservlet and I would like to pass parameters in the url itself. Something like
@WebServlet("/profile/{id}")
public class ProfileServlet extends HttpServlet {
@Override
public void doGet(HttpServletRequest req, HttpServletResponse res) {
String idstr = req.getParameter("id");
int id = idstr == null ? (int)req.getSession().getAttribute("userid") : Integer.parseInt(idstr);
Profile profile = ProfileDAO.getForId(id);
req.setAttribute("profile",profile);
req.getRequestDispatcher("/WEB-INF/profile.jsp").forward(req,res);
}
}
But I can't seem to find anything in the documentation that allows me to do this. I know I could do /profile?idstr=1234 or something, but is there a way I can slap it into the URL with WebServlet? Or do I need a different framework to do this...