1

I want to change My URL name in Java.

Example

Suppose my URL name is www.xyz.com/join.html

I want to change this URL in my address bar to www.xyz.com/register-user

Can anybody suggest any way to achieve this?

Thank You.

4
  • 3
    You could handle this mapping in your web.xml file, see here. Commented Aug 12, 2017 at 6:27
  • @TimBiegeleisen But I want dynamically change my URL suppose my currently Url is example.com/product.jsp?productId=123 and I want to show as example.com/product-name If U know about SEO I want to apply SEO in this Link so any body can visit this and google will find immediately the page. Commented Aug 13, 2017 at 6:08
  • What all are you using? Just the servlets or any other framework? Commented Aug 13, 2017 at 8:56
  • @AbdullahKhan JSP and Servlet Only Commented Aug 13, 2017 at 9:05

1 Answer 1

3

You need to fix your mappings in web.xml

<servlet>
    <servlet-name>RegisterUserServlet</servlet-name>
    <servlet-class>com.blahBlah.RegisterUserServlet</servlet-class> //Your servlets path
</servlet>
<servlet-mapping>
    <servlet-name>RegisterUserServlet</servlet-name>
    <url-pattern>/register-user</url-pattern> //if the url exactly matches register-user RegisterUserServlet will be called.
</servlet-mapping>

Check out this question on SO and this blog for more on what web.xml is.

Sign up to request clarification or add additional context in comments.

4 Comments

You give an answer for servlet but what should be done for JSP?
You can do it the same way. Instead of giving the class path in the servlet-class tag you now have to give path for your jsp's.
Also check out this answer.
Thank You... I think it helps me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.