wood burning stoves 2.0*
The moose likes Servlets and the fly likes Can't access HTML form page in browser Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Can Watch "Can New topic
Author

Can't access HTML form page in browser

Qualtar Demix
Greenhorn

Joined: Mar 14, 2012
Posts: 15
On running the servlet as "Run as Run on server", i am getting the html designed by my servlet. However i cannot get the html form page (that i have manually created to take data) on browser. Please help....
Servlet : LoginServlet.java
Form : login.html

XML file:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!--<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd"> -->
<web-app xmlns:javaee="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>Hello</servlet-name>
<servlet-class>com.sapient.rose.LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Hello</servlet-name>
<url-pattern>/LoginServlet</url-pattern>
</servlet-mapping>

</web-app>


Qualtar Demix
....and I sensed an infinite scream passing through nature
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19759
    
  20

Welcome to the Ranch!

Can you show us your form's opening element?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Qualtar Demix
Greenhorn

Joined: Mar 14, 2012
Posts: 15
hiiiiiii.....

this is my form/html :



john wutka
Ranch Hand

Joined: Apr 14, 2011
Posts: 31
>>>Servlet : LoginServlet.java

Can you please post LoginServlet as well.
Qualtar Demix
Greenhorn

Joined: Mar 14, 2012
Posts: 15
LoginServlet.java



The output i get is :

Thanks Mr. null
Now you can see your password : null

And the url for the above output is:

http://localhost:8080/Testing_Project/LoginServlet

Please help

Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1001
    
    2
checkout the action of your form, because for me your code is working correctly...
i m getting the output is:

Thanks Mr. punit
Now you can see your password : punit
Qualtar Demix
Greenhorn

Joined: Mar 14, 2012
Posts: 15
Hi Punit, i wanna know how exactly are you reaching the form/html page . Are you running LoginServlet.java , simply as "Run as -> Run on server".
Please post the url you are getting for the form/html page.
I think i have something wrong with my web.xml
Can you show your web.xml as well


Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1001
    
    2
form1.html


TestForm.java


web.xml


url m using is:

http://localhost:8080/passValueProblem/form1.html

i m using eclipse.

hope this helps.
Qualtar Demix
Greenhorn

Joined: Mar 14, 2012
Posts: 15
Thanks Punit for uploading these files.
But i am still confused.

You haven't given the fully qualified name of your class in web.xml. On my machine it does not even loads the html created by my servlet.
However, when i give the fully qualified name of class it shows the same null output, again.

Also regarding the url that you have provided. It gives a 404 error on the browser. I have the same port and everything........
I don't understand how the url does not have any mention of the project name.

To be more elaborate....
I am creating "Dynamic Web Project"
A package in src -> com.sapient.rose -> New Class ("LoginServlet.java")
form1.html and web.xml in WEB_INF

Even i am using Eclipse (Version: Indigo Service Release 2)

And i haven't been able to access my form/html page yet.

Can you specify your project structure and how exactly do you run your code.
Please bear with me a little more........

Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

Punit is not using fully qualified name in his web.xml because his servlet exists in the default package.
Something interesting in his post is the following line
Punit Jain wrote:
url m using is:

http://localhost:8080/passValueProblem/form1.html

So he is typing in the URL of the HTML page, not the servlet.

From your post,
Qualter Demix wrote:The output i get is :

Thanks Mr. null
Now you can see your password : null

And the url for the above output is:

http://localhost:8080/Testing_Project/LoginServlet

Its clear that your servlet is generating the output, only thing it complains is that it was not able to read the parameters from the request, this is because there was no request!!

And for the 404, you might need to look closer at

Qualter Demix wrote:

Do you notice something??

Hope this helps


SCJP, SCWCD.
|Asking Good Questions|
Qualtar Demix
Greenhorn

Joined: Mar 14, 2012
Posts: 15
Thanks a lot for narrowing down the problem........
So,
this is because there was no request!!

means that i am not able to send any request
I did my research and in one example i found this....

To debug a HTML form set its 'action' attribute to refernce the Servlet

So, in Punit's example

<form method="GET" action="TestForm">

action=Servlet reference (<servlet-name> in web.xml) ....

Still, after using the url: http://localhost:8080/passValueProblem/form1.html
i am getting 404 error....

NEED MORE HELP
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1001
    
    2
You haven't given the fully qualified name of your class in web.xml. On my machine it does not even loads the html created by my servlet.
However, when i give the fully qualified name of class it shows the same null output, again.


This is because i m using the default package, i have not created any package, as you have created com.sapient.rose..

Also regarding the url that you have provided. It gives a 404 error on the browser. I have the same port and everything........
I don't understand how the url does not have any mention of the project name.


this is also because i have the default package and you have created a package, and you have created.


I am creating "Dynamic Web Project"
A package in src -> com.sapient.rose -> New Class ("LoginServlet.java")
form1.html and web.xml in WEB_INF


I am also using the same procedure but i m doing all this in default package...
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1001
    
    2
Still, after using the url: http://localhost:8080/passValueProblem/form1.html
i am getting 404 error....


you have to give your package name as well, if you are not doing this all in default package..
Qualtar Demix
Greenhorn

Joined: Mar 14, 2012
Posts: 15
Punit i am still getting 404 error on typing this url after running my servlet class

http://localhost:8080/passValueProblem/form1.html



i did some more research and i found this:

The portion of the URL after the http://host:port +WebAppName is compared to the <url-pattern> by WebLogic Server

The url i am getting is : http://localhost:8080/Punit_Project/TestForm (Punit_Project being my "Dynamic Web Project")
Therefore if i don't give any WebAppName it takes the project name as the WebAppName.

In your url passValueProblem must be the WebAppName.

So, can i safely conclude that </display-name> attribute in web.xml defines the WebAppName ???
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

Qualter Demix wrote:Punit i am still getting 404 error on typing this url after running my servlet class

http://localhost:8080/passValueProblem/form1.html


I don't get what running the servlet class actually means. You don't run it, you deploy it on the server.
The HTML page has nothing to do with the servlet, it will be displayed in the browser if it is present at the correct location on the server.

Will you please post your directory structure from the root of your web-app?
I think Eclipse is generating the right folder structure and all but the HTML file is located at a wrong location.

Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

Qualter Demix wrote:
means that i am not able to send any request

Still, after using the url: http://localhost:8080/passValueProblem/form1.html
i am getting 404 error....



It means there is no request which has the form data the servlet is trying to read.

Here the web-app name passValueProblem is important, so is the name of the HTML file and its location.
Have you cross checked if they are all correct?
Qualtar Demix
Greenhorn

Joined: Mar 14, 2012
Posts: 15
My directory structure is:

/Punit_Project/src/TestForm.java
/Punit_Project/WebContent/WEB-INF/web.xml
/Punit_Project/WebContent/form1.html

and to deploy i simply (Run as->Run on server) on TestForm.java
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

When you select Run on server, then a new browser window is opened, whatever address you get there, just remove your servlet's name and add form1.html after the last slash(/).
So for example if the URL displayed is http://localhost:8080/some_project/LoginServlet, change it to http://localhost:8080/some_project/form1.html.
This has to work if the servlet and HTML file are part of the same web-app that is the same web project in eclipse.
Qualtar Demix
Greenhorn

Joined: Mar 14, 2012
Posts: 15
thank you Amit.............thanks a lot......i got the HTML/form page
it is working.............
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

Welcome Qualter
Are you also able to get the parameters you entered in the form on the servlet's response page instead of null values?
Qualtar Demix
Greenhorn

Joined: Mar 14, 2012
Posts: 15
yes i am getting the values as well.

Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

Good work Qualter, keep it going!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can't access HTML form page in browser