• Post Reply Bookmark Topic Watch Topic
  • New Topic

Reset URL to JSP file after servlet call.

 
Nash Walker
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I am a JSP/Servlet newbie currently adding the first servlets to a web site that had been static all along. My local instance worked great but the servlets did not respond on the test instance. Apparently, my hosting service provider requires me to use an invoker servlet mapping.

<servlet-mapping>
<servlet-name>invoker</servlet-name>
<url-pattern>/servlet/*</url-pattern>
</servlet-mapping>


Adding this to local web.xml broke the application but the servlets respond on test instance (when their calls are not preceded by another servlet call). A Servlet fails when it is called immediately after another servlet has been called.

What I saw happening on test is URL for first call is of the form:
xxx.org/<app-name>/servlet/<servlet-name>?Id=1

And URL for the second call became:
xxx.org/<app-name>/servlet/servlet/<servlet-name>?Id=1

The servlets are invoked using "href=servlet/<servlet-name>?Id="

How can I avoid the inclusion of 'servlet' in the URL and reset the URL to the JSP page it navigates to after processing of the servlet? Any kind of help is appreciated.

Thank you very much.

P.S.: I am also trying to enable the Invoker servlet on local so I can troubleshoot easier. I went through the changes to Tomcat's web.xml and context.xml. However, my local servlets did not respond even after calling them using "href=<servlet-name>?Id=". Is there a way I can check if my invoker is active?

 
Paul Clapham
Sheriff
Posts: 21866
36
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your hosting company requires you to use the invoker servlet? Are you sure? Are you sure they said "must"? Have a look at our FAQ page InvokerServlet which explains in much more detail why that's a bad idea.

As for the URLs which your code is generating, our FAQ page RelativeLinks explains how to handle that issue.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65516
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Advice #1: find a better host. A hosting provided who forces you to write things the wrong way is not doing you any favors in trying to learn how to write servlets and JSP. Not one iota.

Advice #2: if Advice #1 cannot be followed for whatever reason, the invoker is disabled by default. And with good reason. it should not be used. Ever. Ever. Never.

Advice #3: see Advice #1 (for emphasis)
 
Nash Walker
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Paul and Bear for your responses. We have sent an email to our hosting provider requesting them to disable the invoker servlet for our account. Paul, the page on contextual path should solve the issues we are facing. Thank you very much for your time.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65516
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch!
 
Nash Walker
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Bear. I hope to become useful to the forum.

So, I read the page on contextual paths and modified my application accordingly. In the meanwhile, I got my hosting provider to disable the invoker servlet as well. Now, the application works in local but does not work on the test server. Could anyone please point to me what I am missing?

This is a URL for a servlet being called on localhost.
http://localhost:8081/myapp/DeleteDocument?Id=18&Ut=admin


This is the URL call for the same servlet on the test instance:
http://www.xxx.org/myapp/DeleteDocument?Id=19&Ut=admin

This is the error message from Apache that is shown in my browser.

Not Found

The requested URL /my-app/DeleteDocument was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

Apache/2.2.22 (Unix) mod_ssl/2.2.22 OpenSSL/0.9.8d mod_jk/1.2.19 Server at www.xxx.org Port 80


The catalina.out has recorded no error messages.

This is the servlet mapping for the DeleteDocument servlet.
<servlet>
<servlet-name>DeleteDocument</servlet-name>
<servlet-class>com.dc.myapp.ui.DeleteDocument</servlet-class>
</servlet>


<servlet-mapping>
<servlet-name>DeleteDocument</servlet-name>
<url-pattern>/DeleteDocument</url-pattern>
</servlet-mapping>


This is how the DeleteDocument servlet is being called:
href = contextPath + DeleteDocument?Id=......


Thank you.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65516
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I get the feeling that the hosting provider does not let you administer your own Tomcat instance? I suspect that they might be sharing Tomcat instances, and hence, you need to follow their rules for deployment. Perhaps that's why they instructed you to use the invoker.

Does your provider have an instruction pare somewhere on how to deploy apps?
 
Nash Walker
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My hosting provider does claim private Tomcat server. I have been given a URL that I can use to re-start my Jakarta-Tomcat server. Hence, I am assuming that is not the case here, although I am unsure about how sharing Tomcat instances would be the cause for the issue described above.

Apps are deployed by FTP to the server and calling the said URL for restarting Tomcat. Earlier, I remember using a URL where I could upload a WAR file for deployment and click buttons on the page for stopping and starting the server, though I can't seem to find it now.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65516
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That control page you recall sounds like the Tomat manager app. That is the best way to make sure your app is deployed.

It's usually mapped to /manager/html but could be mapped otherwise.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!