Avatar billede fredand Forsker
24. oktober 2001 - 18:00 Der er 2 kommentarer og
2 løsninger

Problems with path from servlet to html.

Hello!

I do not like jsp so much I like Servlets better. But I have one big problem when I develop a site with just Servlets, The path/link between a Servlet and a html-page.

Supose that you have a something like this.
A html-page that link to a servlet like:
(in mapp html, file x.html)
<a href=\"servlet/FileManagerTestServlet\"</a>

The Servlet, when executed, prints out the same html-page again, like
1 Read the file x.html
2 Do some change (imagine that you have to change somthing in that page.)
3 Print out that file with a PrintWriter, not with a sendRedirect.

Then we are in mapp /servlet/FileManagerTestServlet so when we click the link again we get a missmatch.

So if any one have some smart solution for this please let me know.

I got 2 solution my self but I do not like them, I guess there must be smarter one, perhaps config the webserver, I run a orion.

Stupid solution 1
When we execute the servlet we replace the path to the right path something like this:
servlet/FileManagerTestServlet => ../servlet/FileManagerTestServlet

Stupid solution 2
We change the path in the x.html file to this
<a href=\"filemanager_forward.jsp\">Filemanager</a>
and add a jsp-page in between with
<jsp:forward page=\"/servlet/FileManagerTestServlet\" />
then the Servlet would execute inside the jsp-page and we would stay in the same folder.


So if any one have a solution with out jsp and replaceing I would be most greatful.

Best Regards

Fredrik

Avatar billede disky Nybegynder
24. oktober 2001 - 21:29 #1
what error do you get ?

I sure don\'t understand why you do not like JSP, with JSP you can do a much greater and better seperation of design (html) and functionality (java)
Avatar billede fredand Forsker
25. oktober 2001 - 12:46 #2
Hello Disky!

The error is that when the servlet has printed out the file x.html (x.html is the file with the link to launch the servlet) again (the second time the x.html is displayed). When we now clicj the link to the servlet the path is not right since we have change the working dir from html to servlet.

I hope this make it a bit easier to understand my problem:
Step 1:
-Workingdir: html
-Action: The user enters the html-page at the adress www.x.com/x.html

Step 2:
-Workingdir: html
-Action: The user clicks the link to the servlet <a href=\"servlet/TestServlet\">Test</a>, notice that we now change the working dir.

Step 3:
-Workingdir: html/servlet
-Action: The Servlet executes and reads the file x.html and prints it out with a PrintWriter. The user will now se the same screen as before he clicked the link. But the different is that we know have change the workingdir.

Step: 4
-Workingdir: html/servlet
-Action: The user tries to click the link again whiche have the code as before = <a href=\"servlet/TestServlet\">Test</a>.

Step: 5
-Workingdir: html/servlet/html/servlet (This working dir doesn\'t exists)
-Action: Since that path is not valid from the html/servlet dir we get a 404. The browser can\'t find that dir.


So my ques is, is it possible to change the configure for the webserver so servlet will execute in html instead of html. Or is there an other solution to this?

The reason that I do not like the JSP is that the designer allways mess up the code at our office, and ofcourse he thinks the same about us. ;-)

So if any one could give me some help here, that would be great.

Best regards

Fredrik






Avatar billede fredand Forsker
29. oktober 2001 - 16:15 #3
Hola Amigos!!

I solved it with adding a tag into the header!
like <base href=\"http://www.test.dk/\">

This set the base for the browser and all links where now strating from this point.

Best Regards

Fredrik

Avatar billede disky Nybegynder
29. oktober 2001 - 16:34 #4
cool :)
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester