• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem getting servlets working

 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am new to AJAX so I was testing my code on the tomcat server by using simple example..... But I am not sure where should I put all the files that have .html extension and where should I put .java file extension and where .class file..
In the WEB-INF/classes folder, my getname.java file and getname.class file is there.. am i doing ryt?
and my ajax.html file is in examples/servlets folder am i doing ryt??
so when I was testing my this code it is not working... everytime i get, error during ajax call...
This is my HTML Code.... saved as ajax.html,



and this is my getname.java file:-




please let me know what wrong I am doing and what other things i have to do.. like i have to add something in web.xml file or sever.xml file....??
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Raihan Jamal wrote:am i doing ryt?


"ryt"? What does that mean?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It would also help to show us the error that you are getting. Otherwise, all we can do is to guess.

Please through the "smart questions" link in my signature.
 
Raihan Jamal
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
am i doing right?
it means that whether I am doing right or not... Since i am not sure where should I put the files... so that's why I asked you...


And How can I show you the error.... I am not sure where should i look for that....
When I opened the page ajax.html....
it doesn't work... instead it shows an alert box message (Error During Ajax call.. Please try again) that I have set up in the Ajax.html page...
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where is that examples/servlets folder placed ?

do place the files in application root , that is convention followed by web app developers.

I guess your ajax request may not be finding the resource at server.
Please make sure you configure the servlet in web.xml.
And also ensure that your ajax request is pointing to resource at Server.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The servlet specification sets out how a web app needs to be laid out. There's also Tomcat documentation.
 
Raihan Jamal
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I placed the .html file here:-
jakarta-tomcat-4.1.27/webapps/examples/servlets/ajax.html

and When I opened ajax.html page so when I click the submit button to test my AJAX Program... it was not working.. instead it shows an alert box that I have set up in ajax.html page...What I am trying to do.. I am calling servlet getname through the button click event in ajax.html page but when I tried to open the servlet directly...
I got these two error:-


1) exception

javax.servlet.ServletException: Cannot allocate servlet instance for path /examples/servlet/getname




2) root cause

java.lang.UnsupportedClassVersionError: getname (Unsupported major.minor version 49.0)


I have added these two lines in web.xml file
<servlet-mapping>
<servlet-name>getname</servlet-name>
<url-pattern>/getname</url-pattern>
</servlet-mapping>

and

<servlet>
<servlet-name>getname</servlet-name>
<servlet-class>getname</servlet-class>
</servlet>

And also ensure that your ajax request is pointing to resource at Server.


how can I make sure about this thing??

 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This has very little to do with Ajax, and everything to do with creating and setting up servlets correctly, so I've moved it to the servlets forum with an appropriate title change.

Two things:

java.lang.UnsupportedClassVersionError: getname (Unsupported major.minor version 49.0)


Means that the JDK being used to compile the class is different than the one being used to run it. Check which JDK versions you are using to complie, and which is being used by Tomcat.

and

<servlet-class>getname</servlet-class>


Servlets must be in a package other than the default.

Also, follow class naming conventions. Class names should be in mixed case -- not all lowercase.

I suggest you back off a bit and write some simple servlets and get them working before trying more complicated things such as Ajax.
 
sriinu reddy
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it's working..
web.xml







document.myForm.message.innerHTML is error prone.

cheers..
srinu


 
Raihan Jamal
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now I am getting this error... As you said I was working with the servlet ryt now... So when I tried to run the servlet directly
then i got this error...

HTTP Status 405 - HTTP method GET is not supported by this URL


my web.xml file has these fields now..

<servlet-mapping>
<servlet-name>getname</servlet-name>
<url-pattern>/examples/servlet/getname</url-pattern>
</servlet-mapping>
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Raihan Jamal wrote:As you said I was working with the servlet ryt now


"ryt" again? Please use real words when posting to the forums. Abbreviations such as "ryt" in place of "right" only serve to make your posts more difficult to read and less likely to generate useful responses.

Please click this link ⇒ UseRealWords for more information.
 
Raihan Jamal
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry again for that

Now I am getting this error... As you said, I was working with the servlet right now... So when I tried to run the servlet directly
then i got this error...

HTTP Status 405 - HTTP method GET is not supported by this URL


my web.xml file has these fields now..

<servlet-mapping>
<servlet-name>getname</servlet-name>
<url-pattern>/examples/servlet/getname</url-pattern>
</servlet-mapping>
 
Ranch Hand
Posts: 247
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you directly send request to Servlet through direct access to the Servlet URL, it goes as GET request ... Since your servlet handles only POST request, you are getting this error... I think you can follow sriinu... Please check again...
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Raihan Jamal wrote:HTTP Status 405 - HTTP method GET is not supported by this URL


As your servlet only implements a POST handler, this should be no surprise.
 
sriinu reddy
Greenhorn
Posts: 11
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rhian first please learn the basics of servlets and then try with ajax.

 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic