Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Java (https://www.askmehelpdesk.com/forumdisplay.php?f=440)
-   -   Servlet,html form problem (https://www.askmehelpdesk.com/showthread.php?t=461352)

  • Mar 30, 2010, 05:46 AM
    hancok
    servlet,html form problem
    Servlet,html form problem?
    Hi,this is hancok.I am getting the error when I click submit button after filling the fileds of the form.
    the eror is as follows.

    This webpage is not found.

    No webpage was found for the web address: file:///C:/formapp/f1?text1=madhu&age=18…

    More information on this error
    Below is the original error message

    Error 6 (net::ERR_FILE_NOT_FOUND): The file or directory could not be found.


    I have the Form1 class in C:\Tomcat 5.0\webapps\formapp\WEB-INF\classes
    I have the classes folder and web.xml in C:\Tomcat 5.0\webapps\formapp\WEB-INF

    my Form1 class is as follows,

    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;

    public class Form1 extends HttpServlet{

    public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{

    response.setContentType("text/html");
    PrintWriter out = response.getWriter();

    String name,add;
    int age;

    name = request.getParameter("text1");
    add = request.getParameter("text3");
    age = Integer.parseInt(request.getParameter("t…

    if(age>=18){

    out.println("<h1>Registration successfully completed");
    out.println("fashion ticket will be dispatched");

    } else{

    out.println("<br> <br>you are not eligible");
    }

    }
    }

    my web.xml is as follows,

    <web-app>

    <servlet>
    <servlet-name>my</servlet-name>
    <servlet-class>Form1</servlet-class>
    </servlet>

    <servlet-mapping>
    <servlet-name>my</servlet-name>
    <url-pattern>/f1</url-pattern>
    </servlet-mapping>
    </web-app>

    i have the form1.html file and WEB-INF in C:\Tomcat 5.0\webapps\formapp

    my html file is as follows,

    <html>

    <head><title>Registration Form</title></head>
    <body>

    <h2><br><br><form name="form1" method="get" action="/formapp/f1">

    Enter name:<input type="text" name=" name=" />

    <br>
    Enter age:<input type="text" />

    <br>
    Enter age:<input type="age" name="text" />
    <br>
    Enter address:<input type="address" name="submit" />
    <br>
    <input type="submit" />
    <br>
    </form>
    </body>
    </html>

    when I click on the html file, then I get ,



    Enter name:
    Enter age:
    Enter address:

    but,after entering details in the fields I click the submit button
    but it won't call the servlet(Form1.java) instead the browser shows the error as follows,

    This webpage is not found.

    No webpage was found for the web address: file:///C:/formapp/f1?text1=ma&age=18&ad…

    More information on this error
    Below is the original error message

    Error 6 (net::ERR_FILE_NOT_FOUND): The file or directory could not be found.
  • May 21, 2010, 06:35 PM
    shaik_hasan

    <html>

    <head><title>Registration Form</title></head>
    <body>

    <h2><br><br><form name="form1" method="get" action="./formapp/f1">

    Enter name:<input type="text" name="text1" />

    <br>
    Enter age:<input type="text" name="age" />
    <br>
    Enter address:<input type="text" name="address" />
    <br>
    <input type="submit" value="submit" />
    <br>
    </form>
    </body>
    </html>

    U modify the HTML file as given above. I did nothing except placing a "." which represents current directory. This wil definetely work.

    Or else do another thing

    MOdidy the XML (web.xml) as follows:

    <web-app>

    <servlet>
    <servlet-name>my</servlet-name>
    <servlet-class>Form1</servlet-class>
    </servlet>

    <servlet-mapping>
    <servlet-name>my</servlet-name>
    <url-pattern>./f1</url-pattern>
    </servlet-mapping>
    </web-app>


    In this also i placed "." in the URL-PATTERN. Check it out. It definitely work.

    Waiting eagerly for your reply/

  • All times are GMT -7. The time now is 02:43 PM.