|
I am beginner to JAVA and I have the following doGet method, and I need to call to from another method
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
String url = "";
if (Code < 0 )
{
url = "/Error.jsp";
}
else
{
url = "/Error.jsp";
}
RequestDispatcher dispatcher =
getServletContext().getRequestDispatcher(url);
dispatcher.forward(request, response);
}
want to know how to call this method from another method, just like the following.
public int getCode()
{
if (stateName.equals("Aden") || stateName.equals("aden") || stateName.equals("ADEN"))
{
Code = 01;
return (Code);
}
else if (stateName.equals("Mukalla") || stateName.equals("mukalla") || stateName.equals("MUKALLA"))
{
Code = 02;
return (Code);
}
else
{
return doGet(request, response);
}
}
the line
return doGet(request, response);
I want to know the correct way of calling?
|
|
|
|
|
You have already shown the correct way of calling it; what is the problem?
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Calling directly doGet or doPost methods is not the correct method. The correct method of calling these methods (i'm assuming they are in a Java servlet) is the following:
Assuming you have a JSP page (at, for example, http://localhost/yourproject/yourjsp.jsp ), you can make requests at that page (GET or POST, it doesn't matter for now).
After you have the JSP page, you need to map it in your web.xml file, in your project, like this:
<servlet-mapping>
<servlet-name>YourServlet</servlet-name>
<url-pattern>/yourpage</url-pattern>
</servlet-mapping>
And then, in your servlet, named in this particular example YourServlet.java , have the doGet / doPost methods, which will get called automatically when you make a request to yourpage.jsp . This is the correct way of calling a doGet or doPost method, and it's rarely (if ever) recommended calling them directly (of course, you can have the other servlet method, processRequest , but that will only forward the request to doGet or doPost).
And in your particular example, you can't call return doGet(request, response) . doGet and doPost are void methods (meaning they don't return anything). Worst case, you can call doGet(request, response) but not return.
Full-fledged Java/.NET lover, full-fledged PHP hater.
Full-fledged Google/Microsoft lover, full-fledged Apple hater.
Full-fledged Skype lover, full-fledged YM hater.
|
|
|
|
|
<pre lang="text"><apispec>
<api version="v1" name="findplaces" provider="ibm" />
<request type="json">
<uri path="/findplaces" mapping="/appengine/data/ibm/places">
[CDATA[List places of a city]]
</uri>
<queryparams>
<param name="country" mapping="/appengine/data/ibm/places/place[@country]">
[CDATA[Country is an attribute of place]]
</param>
<param name="city" mapping="/appengine/data/ibm/places/place[@city]">
[CDATA[City is an attribute of place]]
</param>
<param name="limit" mapping="limit">
[CDATA[Number of places to be returned]]
</param>
</queryparams>
</request>
<response type="json" deflimit="10">
<place name="/appengine/data/ibm/places/place[@name]" city="/appengine/data/ibm/places/place[@city]" country="/appengine/data/ibm/places/place[@country]" address="/appengine/data/ibm/places/place[@address]" zip="/appengine/data/ibm/places/place[@zip]">
<location lat="/appengine/data/ibm/places/place/location[@lat]" long="/appengine/data/ibm/places/place/location[@long]" />
</place>
</response>
</apispec></pre>
|
|
|
|
|
Why do you keep repeating this unreadable post? Please read the suggestions you have been given, edit your question and uncheck the option on the page that says "Treat my content as plain text, not as HTML".
|
|
|
|
|
Dear Richard, i m doing same thing which u told me. I am following ur suggestions but i don't know y u r not able to see. I m posting in plain text format.
|
|
|
|
|
As it's unlikely you will take any notice of my previous suggestion I would refer you to Google that has all these hits[^] for Java SAX.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
do one thing u send me ur mail id and then i will send u that .xml file. plzzzz i need ur help, help me.
|
|
|
|
|
I don't want the XML file. Follow the link I gave you and check out some of the information on using SAX. I'm afraid no one here is going to do it for you.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
|
<pre lang="xml"><apispec>
<api version="v1" name="findplaces" provider="ibm" />
<request type="json">
<uri path="/findplaces" mapping="/appengine/data/ibm/places">
[CDATA[List places of a city]]
</uri>
<queryparams>
<param name="country" mapping="/appengine/data/ibm/places/place[@country]">
[CDATA[Country is an attribute of place]]
</param>
<param name="city" mapping="/appengine/data/ibm/places/place[@city]">
[CDATA[City is an attribute of place]]
</param>
<param name="limit" mapping="limit">
[CDATA[Number of places to be returned]]
</param>
</queryparams>
</request>
<response type="json" deflimit="10">
<place name="/appengine/data/ibm/places/place[@name]" city="/appengine/data/ibm/places/place[@city]" country="/appengine/data/ibm/places/place[@country]" address="/appengine/data/ibm/places/place[@address]" zip="/appengine/data/ibm/places/place[@zip]">
<location lat="/appengine/data/ibm/places/place/location[@lat]" long="/appengine/data/ibm/places/place/location[@long]" />
</place>
</response>
</apispec></pre>
|
|
|
|
|
Please edit this remove the flag 'Treat my content as plain text, not as HTML'
Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
|
|
|
|
|
i need code what u replied, i didn't get
|
|
|
|
|
Your original message cannot be clearly read, so you will not get the help you want, edit it so the tags can be applied properly and make it easier for everyone to read.
Gaurav Sharma from Bangalore, India wrote: i need code
If you need code, then I advise you to write some. If you are having trouble then let us know where you have a problem and then we can help. CP is not here to do your [home]work for you.
Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
|
|
|
|
|
<apispec>
<api version="v1" name="findplaces" provider="ibm" />
<request type="json">
<uri path="/findplaces" mapping="/appengine/data/ibm/places">
[CDATA[List places of a city]]
</uri>
<queryparams>
<param name="country" mapping="/appengine/data/ibm/places/place[@country]">
[CDATA[Country is an attribute of place]]
</param>
<param name="city" mapping="/appengine/data/ibm/places/place[@city]">
[CDATA[City is an attribute of place]]
</param>
<param name="limit" mapping="limit">
[CDATA[Number of places to be returned]]
</param>
</queryparams>
</request>
<response type="json" deflimit="10">
<place name="/appengine/data/ibm/places/place[@name]" city="/appengine/data/ibm/places/place[@city]" country="/appengine/data/ibm/places/place[@country]" address="/appengine/data/ibm/places/place[@address]" zip="/appengine/data/ibm/places/place[@zip]">
<location lat="/appengine/data/ibm/places/place/location[@lat]" long="/appengine/data/ibm/places/place/location[@long]" />
</place>
</response>
</apispec>
|
|
|
|
|
What is the point of reposting the original which is still not correctly formatted? Use <pre> tags around your code block and explain excactly what your problem is.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
<pre lang="xml"><apispec>
<api version="v1" name="findplaces" provider="ibm" />
<request type="json">
<uri path="/findplaces" mapping="/appengine/data/ibm/places">
[CDATA[List places of a city]]
</uri>
<queryparams>
<param name="country" mapping="/appengine/data/ibm/places/place[@country]">
[CDATA[Country is an attribute of place]]
</param>
<param name="city" mapping="/appengine/data/ibm/places/place[@city]">
[CDATA[City is an attribute of place]]
</param>
<param name="limit" mapping="limit">
[CDATA[Number of places to be returned]]
</param>
</queryparams>
</request>
<response type="json" deflimit="10">
<place name="/appengine/data/ibm/places/place[@name]" city="/appengine/data/ibm/places/place[@city]" country="/appengine/data/ibm/places/place[@country]" address="/appengine/data/ibm/places/place[@address]" zip="/appengine/data/ibm/places/place[@zip]">
<location lat="/appengine/data/ibm/places/place/location[@lat]" long="/appengine/data/ibm/places/place/location[@long]" />
</place>
</response>
</apispec></pre>
Gaurav Sharma
|
|
|
|
|
Are you unable to understand the comments or suggestions you have been given? Please stop reposting the same dump and provide the information (properly formatted) that you have been asked for.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
OP has the 'treat as plain text' option on his post.
I have offered to help but he refuses to listen.
Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
|
|
|
|
|
Some people you can't help.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
<pre lang="text"><apispec>
<api version="v1" name="findplaces" provider="ibm" />
<request type="json">
<uri path="/findplaces" mapping="/appengine/data/ibm/places">
[CDATA[List places of a city]]
</uri>
<queryparams>
<param name="country" mapping="/appengine/data/ibm/places/place[@country]">
[CDATA[Country is an attribute of place]]
</param>
<param name="city" mapping="/appengine/data/ibm/places/place[@city]">
[CDATA[City is an attribute of place]]
</param>
<param name="limit" mapping="limit">
[CDATA[Number of places to be returned]]
</param>
</queryparams>
</request>
<response type="json" deflimit="10">
<place name="/appengine/data/ibm/places/place[@name]" city="/appengine/data/ibm/places/place[@city]" country="/appengine/data/ibm/places/place[@country]" address="/appengine/data/ibm/places/place[@address]" zip="/appengine/data/ibm/places/place[@zip]">
<location lat="/appengine/data/ibm/places/place/location[@lat]" long="/appengine/data/ibm/places/place/location[@long]" />
</place>
</response>
</apispec></pre>
|
|
|
|
|
|
Try one of these[^].
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
|
One of these days I'm going to think of a really clever signature.
|
|
|
|