Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 11 of 11

Thread: Help with JSP and Servlets

  1. #1
    Junior Member
    Join Date
    Jul 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help with JSP and Servlets

    Hello, im new to java and to the forum. I'm trying to do a website with java JSP. I have setup tomcat and mysql to run from netbeans. my index.html is located in Wep Pages folder, and my JSP are in WEB-INF and my java code and servelts are in source package folder. My problem is here in my index.html

    <form method=post action="website.Register">
    Select user name: <input type="text" name="user"><br>
    Specify your age: <input type="text" name="age">
    <input type="submit" value="Register"
    </form>

    i'm trying to access the Register java servlet with the post action but when i open it in my browers and click on the link it says:

    HTTP Status 404 - /website.Register

    type Status report

    message /website.Register

    description The requested resource (/website.Register) is not available.

    Is there anything else i should do?? or configure? Thank you for yyour replies .


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Help with JSP and Servlets

    I assume your Register servlet is in a package named website? Depending upon how you've configured the url in the web.xml, there should be no need to specify the package name (you should however specify the .war name that your servlet is located in - if the default url configured in the web.xml is something like '/Register').

  3. #3
    Junior Member
    Join Date
    Jul 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with JSP and Servlets

    yes my servlet is in a package website, but sorry i'm real new to java and even worse to html, this is my first java/website implementation because i have only worked with java files before. So what lines should i type in the web.xml file because i havent edit that file, is just as netbeans created.

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Help with JSP and Servlets

    I don't use netbeans, but am guessing by default the url of the servlet is set to root (eg '/Register'), so try accessing the servlet like:
    '/nameofwar/Register'
    where nameofwar is the name of the package .war file containing the servlet.

  5. #5
    Junior Member
    Join Date
    Jul 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with JSP and Servlets

    I did but still no luck, maybe there is another way to do this without using netbeans?

  6. #6
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Help with JSP and Servlets

    Please post your web.xml
    Last edited by copeg; July 28th, 2010 at 05:45 PM.

  7. #7
    Junior Member
    Join Date
    Jul 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with JSP and Servlets

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
        <servlet>
            <servlet-name>Register</servlet-name>
            <servlet-class>Register</servlet-class>
        </servlet>
        <servlet-mapping>
            <servlet-name>Register</servlet-name>
            <url-pattern>/miami</url-pattern>
        </servlet-mapping>
        <session-config>
            <session-timeout>
                30
            </session-timeout>
        </session-config>
        <welcome-file-list>
            <welcome-file>index.jsp</welcome-file>
        </welcome-file-list>
    </web-app>

    i created a new project miami, same problem
    Last edited by copeg; July 28th, 2010 at 06:01 PM. Reason: Please use the code tags

  8. #8
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Help with JSP and Servlets

    <url-pattern>/miami</url-pattern>
    The above line indicates the url may be specified a bit differently...try:
    /nameofwar/miami

  9. #9
    Junior Member
    Join Date
    Jul 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with JSP and Servlets

    but the name of war is the same as project, so it will be miami/miami??

  10. #10
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Help with JSP and Servlets

    Did you try it?

  11. #11
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: Help with JSP and Servlets

    First of all is this the fully qualified package and class name?

    <servlet-class>Register</servlet-class>
    Second, this is just fine

    <url-pattern>/miami</url-pattern>
    The above url pattern means that the link to the servlet will be this


    Are you seeing any errors when you hit the link other than 404 or do you see anything in catalina.out/tomcat log files?

    // Json

Similar Threads

  1. Initialization parameter of servlets
    By rakesh in forum Java Servlet
    Replies: 3
    Last Post: April 13th, 2010, 03:14 AM
  2. Servlets and HttpSession
    By DC200 in forum Java Networking
    Replies: 3
    Last Post: November 17th, 2009, 03:32 AM
  3. [SOLVED] Using html Radio Buttons with Servlets
    By oss_2008 in forum Java Servlet
    Replies: 2
    Last Post: June 25th, 2009, 05:39 AM
  4. Replies: 1
    Last Post: May 19th, 2009, 09:19 AM
  5. [SOLVED] How to link two servlets?
    By bhmadhukar in forum Java Servlet
    Replies: 4
    Last Post: May 19th, 2009, 08:24 AM