aspose file tools*
The moose likes Servlets and the fly likes Servlet auto redirect to another page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet auto redirect to another page" Watch "Servlet auto redirect to another page" New topic
Author

Servlet auto redirect to another page

nick tomer
Greenhorn

Joined: Oct 18, 2010
Posts: 26
Hi, I have 2 servlets. Servlet A in computer A and Servlet B in computer B runnng on tomcat 7. In servlet A i have a link <a href="http://computerB:8080/Servlet B">link</a> that calls Servlet B Giving to it some parameters.
Servlet B takes these parameters and creates an xml string.
My first question is how the servlet B will the xml string automaticly back to Servlet A? I tried the response.sendredirect("http://computerA:8080/ServletA") but it doesn't work.
Do you have any idea?

My secod question: is there any tool that calculate the time between request and response? I want to compare web services and servlets. Which is more fast?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61010
    
  65

Please read ItDoesntWorkIsUseless.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
nick tomer
Greenhorn

Joined: Oct 18, 2010
Posts: 26
Sorry for the "it doesn't work".

I solved my first question.

My second question remains.
is there any tool that calculate the time between request and response? I want to compare my code with web services implementation and servlets implementation. Which is more fast, etc?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

I'm sure you could write a simple servlet filter which did that calculation for all requests.
nick tomer
Greenhorn

Joined: Oct 18, 2010
Posts: 26
I read a little bit about the filters and i have some questions that i couldn't found any answer.

The FilterChain.doFilter(request,response) method is used to invoke the next filter in the chain. How it knows which is the next filter?
Where i am going to write the filter code? Inside the code of servlet A?
The Servlet A calls the filter-> the filter calls Servlet B -> Servlet B returns result to Filter and filter return the results to Servlet A?

Thanks
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

You didn't read very far then. The filters are called before any servlets. And they are processed in the same order they appear in the web.xml file... not that it usually makes any difference.

And you write the filter code in the filter. Didn't what you read have some examples of servlet filters? If not then you should find that. Google keywords: servlet filter tutorial.

And no, servlets don't "call" any filters. It's receiving a request from a client which causes the filters to be run.
nick tomer
Greenhorn

Joined: Oct 18, 2010
Posts: 26
Honestly i searched in google with the right keywords but there are not many full axamples. the most of them are shoing the code of filter class.
I will study more.

the other thing is tha eclipse does not create a web.xml file so i cannot configure the filter order.
If i am wrong about that let me know.

thanks
Ilari Moilanen
Ranch Hand

Joined: Apr 15, 2008
Posts: 198
This was one of the first results with the keywords that Paul provided
http://javaboutique.internet.com/tutorials/Servlet_Filters/index.html
(note that the tutorial consists of several pages)

If eclipse is not creating the web.xml for you then you have wrong kind of project. Is your project "Dynamic web project", "Jsp" or "Servlet" project? Or some other?

In any case if Eclipse is not creating the web.xml for you then what is? Are you creating it manually with a text editor? You should have a web.xml file in your application. I do not say it is required since for example tomcat provides a default web.xml
nick tomer
Greenhorn

Joined: Oct 18, 2010
Posts: 26
I will take a look the link you sent me.
all my projects in eclipse are web dynamic projects.
in one of my projects i have created 10 servlets that works perfectly but there is no web xml in my whole workspace that maps my servlets.

http://www.coderanch.com/t/514873/vc/Eclipse-web-xml-servlet-mapping
Ilari Moilanen
Ranch Hand

Joined: Apr 15, 2008
Posts: 198
based on that topic and what you say in this topic you seem to be content with the situation that you have no web.xml. One might even say that you seem to be proud of it. Good luck with that decision!
nick tomer
Greenhorn

Joined: Oct 18, 2010
Posts: 26
No. i'd rather to have a web xml but i don't know how. It is weird to me that there is no web.xml but all of my servlets works properly.
I hope to figure it out.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61010
    
  65

You could always make your own. Relying on an IDE to do everything for you won't help you learn anything.
nick tomer
Greenhorn

Joined: Oct 18, 2010
Posts: 26
Ok thanks a lot. I'll start experimenting on that.
 
jQuery in Action, 2nd edition
 
subject: Servlet auto redirect to another page