How to create url in servlet?

I want to know how to create a url in a servlet. I have a registration servlet, and every time I add a user I want gen. URL for each user profile. Can anybody help me?

+3
source share
4 answers

I think kgiannakakis solution is very good. I just want to add some details, because while reading Agusti-N's comment, I have a suspect, maybe he is missing something.

Let's say that you have a UsersServlet described by kgiannakakis, jsp called showUserProfile.jsp and userBean , which has all the properties, the user profile should be displayed in jsp.

When a new user logs into your application, you only need to do more than what you are already doing now. Just register a new user in db and forget the registration servlet .

Now suppose I signed up for your application with my username alexmeia .

- yourApp/Users/alexmeia, UsersServlet . alexmeia URL- , , userBean.

showUserProfile.jsp, , userBean.

, alexmeia Db, userNotFound.jsp ...

. URL .

+2

- :

  <servlet-mapping>
    <servlet-name>UsersSelvlet</servlet-name>
    <url-pattern>/Users/*</url-pattern>
  </servlet-mapping>

, MyApp/Users/UserId, , userId , . " ". .

RESTful.

+7

, REST. , .

+1

URL? , - this, RMI

0

Source: https://habr.com/ru/post/1704654/


All Articles