[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 873
  • Last Modified:

netbeans

I am using netbeans, and when i try to debug my java class file, it says here below, what do i do next?

there are no servlet mappings specified in web.xml for hello servlet\



Moiz
0
Moizsaif123
Asked:
Moizsaif123
  • 4
  • 3
  • 2
1 Solution
 
suprapto45Commented:
Hi Moiz,

What you need to do after you create your servlet is to actually map it in your web.xml.

For example, in your JSP, you have a kind of this.
<form action="/MyServlet">
.
.
.
</form>

Then, you should have your MyServlet.java such as
public class MyServlet extends HttpServlet
{
   
}

Then, in order for your JSP to run your Servlet, in your web.xml, you should have

    <servlet>
        <servlet-name>MyServlet</servlet-name>
        <servlet-class>com.yourpackage.MyServlet</servlet-class>
    </servlet>

and

    <servlet-mapping>
        <servlet-name>MyServlet</servlet-name>
        <url-pattern>/MyServlet</url-pattern>
    </servlet-mapping>


I hope that helps.

regards
Dave
0
 
suprapto45Commented:
Hi,

I do not know how to do it in netbeans. You can do it manually though :).

Regards
Dave
0
 
Moizsaif123Author Commented:
this is what my xml file looks like now, when i put the servlet mapping tag in here it gives me design time errors, where can i put it in here...


<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://java.sun.com/xml/ns/j2ee/#resources"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
       version="2.4">
         
         
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
   
    <welcome-file-list>
   
   
      <welcome-file>
            index.jsp
        </welcome-file>
      <welcome-file>
            index.html
        </welcome-file>
      <welcome-file>
            index.htm
        </welcome-file>
    </welcome-file-list>
</web-app>
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
suprapto45Commented:
Hi,

It should be

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
                         "http://java.sun.com/dtd/web-app_2_3.dtd">
<!-- Copyright (c) 2002 by ObjectLearn. All Rights Reserved. -->
<web-app>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>

    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
    <error-page>
        <error-code>404</error-code>
        <location>/error.jsp</location>
    </error-page>  
     
    <servlet>
        <servlet-name>MyServlet</servlet-name>
        <servlet-class>com.yourpackage.MyServlet</servlet-class>
    </servlet>
 
       
     <servlet-mapping>
        <servlet-name>MyServlet</servlet-name>
        <url-pattern>/MyServlet</url-pattern>
    </servlet-mapping>

Regards
Dave
   

</web-app>
0
 
suprapto45Commented:
Hi,

Ignore my previous message. It was typo. It should be

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
                         "http://java.sun.com/dtd/web-app_2_3.dtd">
<!-- Copyright (c) 2002 by ObjectLearn. All Rights Reserved. -->
<web-app>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>

    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
    <error-page>
        <error-code>404</error-code>
        <location>/error.jsp</location>
    </error-page>  
     
    <servlet>
        <servlet-name>MyServlet</servlet-name>
        <servlet-class>com.yourpackage.MyServlet</servlet-class>
    </servlet>
 
       
     <servlet-mapping>
        <servlet-name>MyServlet</servlet-name>
        <url-pattern>/MyServlet</url-pattern>
    </servlet-mapping>

</web-app>


Regards
Dave
   
0
 
maXXXeECommented:
click on the "web.xml" under the "WEB-INF" folder in the projects window.
then select the "servlets" tab
click on the "Add Servlet Element" button

NOTE:This method is for netbeans 4.0 and above
0
 
Moizsaif123Author Commented:
you mean right click the web.xml and select servlets tab?

I dont see any add servlet element button....
0
 
maXXXeECommented:
no, u hav to double click on web.xml (or) right click and select open
when it is opened on the top of the document u will see "overview", "servlets", "filters" etc...
click on servlets and u can find "add servlet element"
0
 
Moizsaif123Author Commented:
well apparently I am using this tutorial link below...

http://www.netbeans.org/kb/articles/quickstart-webapps-40.html

and i got to call the class using netbeans...

however i dont undestand whats this mean....Overriding an Ant property


and what is a jar file....
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now