How to create user friendly links?

Hi there;

I am not new on Java but i never know about this subject. So i need help. What i want to do is; for example i have links like below on my website and change the links below;

index.jsp

login.jsp

albums.jsp

into;

index

login

albums

So how am i going to make this mapping? By the way i dont want the user to reach my pages typing any ".jsp" string the end of the links

Note:I am working with standart jsp connected to java classes

thank you

Burak

[533 byte] By [netsonicca] at [2007-11-27 11:05:12]
# 1

Use a servlet as a controller. Use whatever URL mapping you want.

~

yawmarka at 2007-7-29 13:07:02 > top of Java-index,Java Essentials,New To Java...
# 2

Can you please give me details what type of controller servlet is it?

I can map the servlets which i post some parameter for process but the rest of the jsp's include web design... I cannot make them directly a servlet...

netsonicca at 2007-7-29 13:07:02 > top of Java-index,Java Essentials,New To Java...
# 3

any response plz?

netsonicca at 2007-7-29 13:07:02 > top of Java-index,Java Essentials,New To Java...
# 4

> Can you please give me details what type of

> controller servlet is it?

You need to learn about Servlets and then come back here. The reply is telling you to write a Servlet class to act as the controller in your application.

> I can map the servlets which i post some parameter

> for process but the rest of the jsp's include web

> design... I cannot make them directly a servlet...

You're missing the point. Nobody is asking you to make your JSP's into Servlets (although that's what they'll end up being anyway). The suggestion was to write a controller Servlet.

SoulTech2012a at 2007-7-29 13:07:02 > top of Java-index,Java Essentials,New To Java...
# 5

is this servlet controller related with Java Filter package?

netsonicca at 2007-7-29 13:07:02 > top of Java-index,Java Essentials,New To Java...
# 6

http://java.sun.com/blueprints/patterns/FrontController.html

http://java.sun.com/blueprints/corej2eepatterns/Patterns/FrontController.html

DrClapa at 2007-7-29 13:07:02 > top of Java-index,Java Essentials,New To Java...
# 7

i have readed the links you gave thank you...

i have found servlet mapping paremeters below that is working well;

<servlet>

<servlet-name>Photos</servlet-name>

<jsp-file>workfolder/photos.jsp</jsp-file>

</servlet>

<servlet-mapping>

<servlet-name>Photos</servlet-name>

<url-pattern>/photos</url-pattern>

</servlet-mapping>

now i can call my pages like;

mydomain.com/photos?id=2

what i also want to do is to send parameters like below;

mydomain.com/photos/2

is it possible to make this with servlet mapping or do i strictly have to use a servlet controller?

null

netsonicca at 2007-7-29 13:07:02 > top of Java-index,Java Essentials,New To Java...
# 8

AFAIK the servlet mapping on the deployment descriptor can't be parameterized. Use an ordinary servlet on which you'd do a redirect or a request dispatching.

hiwaa at 2007-7-29 13:07:02 > top of Java-index,Java Essentials,New To Java...
# 9

http://java.sun.com/blueprints/patterns/FrontController.html

I have re-read the documentation carefully. It really looks like what i need. I understood the logic but not completely because the example java classes contain too much code and i couldnt find where it parses my url for example;

mydomain.com/photos/2

into

mydomain.com/photos?id=2

please if you know a more clear or simple example of front controller system give me.

Thanks

netsonicca at 2007-7-29 13:07:02 > top of Java-index,Java Essentials,New To Java...
# 10

By the way how the front controller is going to catch all of my requests? Do i must add something to web.xml?

i really need a live example that works...? Please help!

netsonicca at 2007-7-29 13:07:02 > top of Java-index,Java Essentials,New To Java...
# 11

> By the way how the front controller is going to catch

> all of my requests?

By configuring the servlet request mapping in web.xml to direct all incoming requests to the front controller.

~

yawmarka at 2007-7-29 13:07:02 > top of Java-index,Java Essentials,New To Java...
# 12

Here i made a summary of the controller servlet, its a template which i have summarized from the documents. Please correct me and i have some questions.

package com.mydomain;

import javax.servlet.RequestDispatcher;

import javax.servlet.ServletConfig;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletResponse;

import javax.servlet.http.HttpServletRequest;

public class Controller extends HttpServlet {

public void init(ServletConfig config) throws ServletException {

super.init(config);

}

public void destroy() {

}

protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException {

String page="";

//my processes to parse servlet request url

dispatch(request, response, page);

}

protected void doGet(HttpServletRequest request,

HttpServletResponse response)

throws ServletException, java.io.IOException {

processRequest(request, response);

}

protected void doPost(HttpServletRequest request,

HttpServletResponse response)

throws ServletException, java.io.IOException {

processRequest(request, response);

}

protected void dispatch(HttpServletRequest request,

HttpServletResponse response,

String page)

throws javax.servlet.ServletException,

java.io.IOException {

RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(page);

dispatcher.forward(request, response);

}

}

My questions:

1)Is my template correct? Or is there any main controller method missing?

2)What is init method for?

3)What is destroy method for? Do i need them?

I will parse the url within the processRequest method and will create my backside link... And dispatch the servlet to the link i have created. Thats all

Make me clear and get the duke dollars :)

Thank you all

netsonicca at 2007-7-29 13:07:02 > top of Java-index,Java Essentials,New To Java...
# 13

> My questions:

1)Is my template correct? Or is there any main controller method missing?

Have you tested it? Does it work the way you expect?

> 2)What is init method for?

It's called as part of the servlet lifecycle.

http://java.sun.com/j2ee/1.4/docs/tutorial/doc/Servlets.html#wp69957

3)What is destroy method for? Do i need them?

It's called as part of the servlet lifecycle.

http://java.sun.com/j2ee/1.4/docs/tutorial/doc/Servlets.html#wp69957

> I will parse the url within the processRequest method and will create my backside link... And dispatch the servlet to the link i have created.

Sounds like a fair enough plan. But remember that you're not "creating a link"; you're determining the name of a resource on the server and forwarding the request to that resource.

> Make me clear and get the duke dollars :)

Dukes are pretty much worthless around here. Most regular folks answer questions because they like to, not because they think they'll get Dukes.

~

yawmarka at 2007-7-29 13:07:02 > top of Java-index,Java Essentials,New To Java...
# 14

Sorry about duke dollars subject it was just an empty sentence. I am here in this forum during 3 years not for duke dollars sure:)

1) I will test it and write here again. The idea about my template was just to ask if i am in the correct direction.

2) I have another servlets which i have coded before and havent used destroy or init. As i know the garbage collector makes it automatically. Do we strictly use init and destroy and call it from somewhere in code?

3) I want to give you duke dollars:)

i will return after testing my template...Thanks a lot

netsonicca at 2007-7-29 13:07:02 > top of Java-index,Java Essentials,New To Java...
# 15

> 1) I will test it and write here again. The idea

> about my template was just to ask if i am in the

> correct direction.

It looks like you're headed in the right direction.

> 2) I have another servlets which i have coded before

> and havent used destroy or init. As i know the

> garbage collector makes it automatically. Do we

> strictly use init and destroy and call it from

> somewhere in code?

No. The servlet container calls those methods. You would override them if you need some special behavior during initialization or destruction (e.g., setup objects, clean up resources, etc.).

> i will return after testing my template...Thanks a lot

You're very welcome.

~

yawmarka at 2007-7-29 13:07:09 > top of Java-index,Java Essentials,New To Java...