This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Servlet" Watch "Servlet" New topic
Author

Servlet

Swapnil Sanghai
Ranch Hand

Joined: Dec 05, 2011
Posts: 41

Hi all,
I am trying to deploy my projects site. In which i am using servlet and jsp. My directory structure is as follows

HAS--->WEB-INF--->classes

HAS is the root directory for my project where I placed all the .html and .jsp files. In WEB-INF I placed the web.xml and created a classes directory shown as above. In classes directory I placed the .class files. When I entered the URL localhost:8080/HAS/login.jsp"

it doesn't show anything. So what is wrong there. Please tell me.
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1686
    
  25

Hi Swapnil,

What server are you using? How did you deploy your webapp? Did you see any errors on the server-console when starting up?

Regards,
Frits
Durgesh Vaishnav
Greenhorn

Joined: Oct 06, 2006
Posts: 16

In addition of Frits question, Also check your context root setup property, with context root URL can be "localhost:8080/HAS/login.jsp" otherwise "localhost:8080/login.jsp"


Enthusiasm is the engine of success!!
SCJP 1.4, OCPJP6
Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1509
    
    5

Also check the output of
http://localhost:8080


Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
Swapnil Sanghai
Ranch Hand

Joined: Dec 05, 2011
Posts: 41

Hi all,
First thanls for your guidence. Now the .jsp and .html pages are running browser window is showing the output now the problem of the servlet came into picture. When I click the submit button it shows that it couldn't find the resource that I given to the servlet. In deployment descriptor I have given only the servlet-name, servlet-class and the url-pattern.
The following are the lines from web.xml




Now what will be the error in my code. I am unable to find it. Please help me for that.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61305
    
  66

One problem that I see is that your servlet class is not in a package.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Swapnil Sanghai
Ranch Hand

Joined: Dec 05, 2011
Posts: 41

Thanks Bear.
Is it compulsory to put the servlet class file in package.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61305
    
  66

Yes. Yes. A thousand times yes. Put all classes everywhere in a package.
Swapnil Sanghai
Ranch Hand

Joined: Dec 05, 2011
Posts: 41

Hello Bear,
This time I have created the package structure as follows for .class file

classes-->com-->example-->web-->Authorization.class

and in the web.xml file I have given the class's address as

com.example.web.Authorization

even then it is not showing my output where I am wrong now.
Everything is same now as previous except that the new modified directory structure.
I am using Tomcat 7.0.x.
Mayur Shinde
Greenhorn

Joined: Feb 15, 2012
Posts: 18
Swapnil Sanghai wrote:Hi all,
I am trying to deploy my projects site. In which i am using servlet and jsp. My directory structure is as follows

HAS--->WEB-INF--->classes

HAS is the root directory for my project where I placed all the .html and .jsp files. In WEB-INF I placed the web.xml and created a classes directory shown as above. In classes directory I placed the .class files. When I entered the URL localhost:8080/HAS/login.jsp"

it doesn't show anything. So what is wrong there. Please tell me.


First of all edit your server.xml file which is in tomcat directory, in server.xml file there is one tag <serverconnector port=8080>(similar to that) change port no from 8080 to something else like 8040, and then start your server by clicking startup.bat. Now type http://localhost:8040/, if you get some web page regarding your server info, it means that server is running and there is no issue regarding server, If it didn't appear then Have you set java_home and classpath variable? and also you have to add welcome file tag in Deployment descriptor. because by default it is index.html. Even if problem persist then let me know.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61305
    
  66

Swapnil Sanghai wrote:even then it is not showing my output where I am wrong now.

At least that is now eliminated a problem source. But apparently it was not the only problem.

Swapnil Sanghai
Ranch Hand

Joined: Dec 05, 2011
Posts: 41

@Mayur: I already set the port number to 9090 as I am having oracle running on 8080. There is no problem regarding the startup of server. It is running. I just want to know that where I made mistake in web.xml as I am unable to cal servlet from my jsp page.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61305
    
  66

Show us the updated deployment descriptor, the context path upon which you've deployed the web app, and the URL that you are trying to use to invoked the servlet.
Swapnil Sanghai
Ranch Hand

Joined: Dec 05, 2011
Posts: 41

Thanks for your suggestions.
I got my error. Everything was right in the deployment descriptor. The error was in the servlet code. I was not following the rules of overriding. So thats why it wasn't showing me the output.
 
GeeCON Prague 2014
 
subject: Servlet