aspose file tools*
The moose likes Servlets and the fly likes Problem with simple HTML - Servlet login Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Problem with simple HTML - Servlet login" Watch "Problem with simple HTML - Servlet login" New topic
Author

Problem with simple HTML - Servlet login

Alex Parvan
Ranch Hand

Joined: Dec 10, 2009
Posts: 115
Hello,

If i open http://localhost:8080/EETest-war/servlet/LoginServer i get a simple html login page:


When i press the submit button, i get the page not found error. I've tried every possible combination in action="". Maybe someone can point out what i do wrong, here is the web.xml:


And the servlet:


I really hope someone can help, i'm stuck :P Thank you


"Quoting yourself is stupid" - Me
avi sinha
Ranch Hand

Joined: Mar 15, 2009
Posts: 453

change the form action to



edited : i hadn't seen the current page location .

avi sinha


SCJP 5.0 SCWCD 5.0
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61768
    
  67

You have an HTML file defined as a servlet?

Why did you bother to write the servlet if you are not going to use it?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61768
    
  67

avi sinha wrote:change the form action to
No. Do not.

Relative paths are a disaster. Your paths should always start with the context path.

What needs to be fixed is the deployment descriptor.
avi sinha
Ranch Hand

Joined: Mar 15, 2009
Posts: 453

Bear Bibeault wrote:
avi sinha wrote:change the form action to
No. Do not.

Relative paths are a disaster. Your paths should always start with the context path.

What needs to be fixed is the deployment descriptor.


meanwhile you were typing . i corrected sir. my mistake.

avi sinha
avi sinha
Ranch Hand

Joined: Mar 15, 2009
Posts: 453

sorry sir again.
i thought the location stated above is the location for the html file from where post method is being called .

DD should be



and the html file should be



avi sinha
Alex Parvan
Ranch Hand

Joined: Dec 10, 2009
Posts: 115
Thanks for the answer. With the new settings i get this error:

HTTP Status 404 -

type Status report
message
descriptionThe requested resource () is not available.

I don't even get the Login screen anymore, i just get this error.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61768
    
  67

What new settings? If you don't show them, how can we help?

And one crucial piece of information you haven't yet supplied: what is the context path?
Alex Parvan
Ranch Hand

Joined: Dec 10, 2009
Posts: 115
The ones avi sinha posted.

Edit: Context path is /EETest-war
avi sinha
Ranch Hand

Joined: Mar 15, 2009
Posts: 453

Parvan Alexandru wrote:Thanks for the answer. With the new settings i get this error:

HTTP Status 404 -

type Status report
message
descriptionThe requested resource () is not available.

I don't even get the Login screen anymore, i just get this error.


the reason is that you haven't defined the mappings for the servlet you are trying to use.
the mapping you have provided in the DD is for the jsp file not for the servlet.

avi sinha
Alex Parvan
Ranch Hand

Joined: Dec 10, 2009
Posts: 115
Could you please show me what i should write so it can run ? I'm learning the hang of it and it would be easier if i had the correct version so i can see what i'm missing.

Thank you.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61768
    
  67

Those are not correct. What is the purpose of the jsp-file entry?

Declaring a servlet is as simple as:


And, your servlet must be in a package.
avi sinha
Ranch Hand

Joined: Mar 15, 2009
Posts: 453

Parvan Alexandru wrote:Could you please show me what i should write so it can run ? I'm learning the hang of it and if i don't see the correct version, i really don't understand what i'm missing.

Thank you.


at first tell me these things then we can help :

1> name of your web-app. is it servlet no its /EETest-war. am i right??
2> name of the first html page you are using to call the post method of servlet
3> package structure of the servlet class i.e. where have you kept the class file ?

avi sinha
Alex Parvan
Ranch Hand

Joined: Dec 10, 2009
Posts: 115
I'm using NetBeans. The project name is EETest and it's using EETest-war as a client module (that's where all the files are).

C:\Users\Infernal\Documents\Java\EETest\EETest-war\build\web\WEB-INF\classes - the class folder

pub_login.html - the first html page

I attached a screen with the project.


[Thumbnail for Untitled.jpg]

Alex Parvan
Ranch Hand

Joined: Dec 10, 2009
Posts: 115
Bear Bibeault wrote:And, your servlet must be in a package.

Why ? I'll try...
avi sinha
Ranch Hand

Joined: Mar 15, 2009
Posts: 453

Parvan Alexandru wrote:
Bear Bibeault wrote:And, your servlet must be in a package.

Why ? I'll try...


otherwise you will not be able to use it as per the specification.

avi sinha
avi sinha
Ranch Hand

Joined: Mar 15, 2009
Posts: 453

if you are trying to learn servlets using Netbeans or any other ide , you are doing it wrong.
there are a lot of concepts you should know and i bet you can't learn them using an ide .
so my suggestion is :
try to do it without using an ide. and its quite traumatic for us to help you if you are using an ide.

avi sinha
avi sinha
Ranch Hand

Joined: Mar 15, 2009
Posts: 453

ok i am trying again . hope you can understand

html file Loginserver http://localhost:8080/EETest-war/servlet/LoginServer


DD:



and put the LoginServlet class file in WEB-INF-->com-->web-->
and restart the server
Alex Parvan
Ranch Hand

Joined: Dec 10, 2009
Posts: 115
I have tried tutorials, books, they all explain it in a different way, and it never works. NetBeans does some of the work for me and it's the first time i got this far.

I can't get server-class right, if it's in package "pack", shouldn't it look like this:
avi sinha
Ranch Hand

Joined: Mar 15, 2009
Posts: 453

Parvan Alexandru wrote:I have tried tutorials, books, they all explain it in a different way, and it never works. NetBeans does some of the work for me and it's the first time i got this far.

I can't get server-class right, if it's in package "pack", shouldn't it look like this:


i have posted the correct code for your app . check that.
and mind it : its the Netbeans who is doing your work not you. grab a copy of head first servlets and jsp and i am sure you will do it on your own.

avi sinha
Alex Parvan
Ranch Hand

Joined: Dec 10, 2009
Posts: 115
I still get the same error

HTTP Status 404 -

type Status report
message
descriptionThe requested resource () is not available.

Without getting the login screen. Isn't this wierd ?

I really want to thank you for your patience with me.
avi sinha
Ranch Hand

Joined: Mar 15, 2009
Posts: 453

Parvan Alexandru wrote:I still get the same error

HTTP Status 404 -

type Status report
message
descriptionThe requested resource () is not available.

Without getting the login screen. Isn't this wierd ?

I really want to thank you for your patience with me.


ok wait for a while i am going to code a small web-app for you to make you understand the whole scenario.

avi sinha
avi sinha
Ranch Hand

Joined: Mar 15, 2009
Posts: 453

sample web-app

unzip the file in your server's web-app directory and then in your browser open up http://localhost:8084/TestServlet/web
please restart the server before opening the page
avi sinha
Alex Parvan
Ranch Hand

Joined: Dec 10, 2009
Posts: 115
Now i get:

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

type Status report
messageHTTP method GET is not supported by this URL
descriptionThe specified HTTP method is not allowed for the requested resource (HTTP method GET is not supported by this URL).

Anyway, i'll try more tomorrow (it's almost 3 AM here), i'll figure it out in the end. Thanks for the help.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61768
    
  67

Look at your servlet. It's quite clear why you get that message.
Alex Parvan
Ranch Hand

Joined: Dec 10, 2009
Posts: 115
I've done it. And with your help, thank you so much.
First of all, i have to access http://localhost:8080/EETest-war where the login page is at. And when i press the submit button, it calls /EETest-war/Login.

Here is my final code:

Servlet:


HTML:


web.xml file:


Thank you soooo much !
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with simple HTML - Servlet login