Results 1 to 6 of 6

Thread: JSP form - error in sending request

  1. #1
    Join Date
    Dec 2009
    Posts
    192

    JSP form - error in sending request

    Hello
    I have an error in sending request from a jsp form. This is my source code below
    Code:
    <form action ="index.jsp" method ="post">
    <table>
    <tr>
    <th> Name: </ th> <td> <input type ="text" name ="name" > </ Td>
    </ tr>
    <tr>
    <th> Surname: </ th> <td> <input type ="text" name ="nome" > </ td>
    </ tr>
    </ table> <br>
    <input type ="submit" >
    <input type ="reset">
    </ form>
    I then retrieves the data sent through the request object:
    Code:
    <%
    String name = request.getParameter("name");
    String lastname = request.getParameter("nome");
    %>
    By this is giving me an error, can any one help with this.

  2. #2
    Join Date
    Feb 2008
    Posts
    1,852

    Re: JSP form - error in sending request

    Hello,
    Just check out this code, this may help you.
    Code:
    String sqltest = "insert into person (name, surname) values (?,?)"
    PreparedStatement st = con.prepareStatement(sqltest);
    
    st.setStringl(1, name);
    st.setStringl(2, lastname);
    
    st.executeUpdate();
    Just try out this, if it does not works then post back with your query.

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: JSP form - error in sending request

    Hi,
    The above program can help you, or else you can try this code.
    Code:
    <% @ Page import = "java.sql .*"%>
    <%
    try
    {
    Class.Class.forName("com.mysql.jdbc.Driver");
    }
    catch(SQLException e)
    {
    System.Out.System.out.println("Can not load nn");
    }
    String testurl = "jdbc: mysql: / / localhost: 3306 (port) / nombasedonne";
    try
    {
    
    java.sql.Connection conn = DriverManager.getConnection(testurl, user, password);
    Statement stmt = conn.createStatement();
    stmt.executeQuery("insert into person (name, surname) values ("+ name +","+ lastname +")");
    }
    catch(Exception e)
    {
    System.Out.System.out.println(e);
    }
     
    %>

  4. #4
    Join Date
    Oct 2005
    Posts
    2,393

    Re: JSP form - error in sending request

    Hello,
    Try this code, this is easier to understand and implement
    Code:
    <% @ Page import = "java.sql .*"%>
     
    <%
    Class.Class.forName("com.mysql.jdbc.Driver");
    String testurl = "jdbc: mysql: / / local / person? user = root";
    Connection conn = DriverManager.getConnection(testurl);
    Statement stmt = conn.createStatement();
    String myName = request.getParameter("name");
    String myUpdated = request.getParameter("nome");
    stmt.executeQuery("insert into person (name, surname) values ("+ myName +","+ + myUpdated")");
    %>

  5. #5
    Join Date
    Jan 2008
    Posts
    1,521

    Re: JSP form - error in sending request

    Hello,
    I think you have errors in your code. Regarding affect your inclusion in one click, just put an input type submit, and your treatment you do it in a servlet, for example.
    <form method ="POST">
    <input type = submit name ="insertionBdd" value ="Add" />
    </ form>
    The POST method in your servlet is,
    if(request.getParameter("insertionBdd") != null){
    treatment based on your + redirection
    }
    Just correct it, and then run the program.

  6. #6
    Join Date
    May 2008
    Posts
    2,389

    Re: JSP form - error in sending request

    Hello,
    I think the configuration of your servlet should be some thing like this
    Code:
    <servlet>
            <servlet-name> nser </ servlet-name>
            <servlet-class> com.Servlet.nser</ servlet-class>
        </ servlet>
    
    ...
    
     <servlet-mapping>
            <servlet-name> nser </ servlet-name>
            <url-pattern> / nmServlet </ url-pattern>
        </ servlet-mapping>
    Last edited by opaper; 18-01-2010 at 02:07 PM.

Similar Threads

  1. Replies: 5
    Last Post: 16-02-2012, 03:27 AM
  2. Replies: 3
    Last Post: 20-01-2012, 08:46 PM
  3. Sending a POST Request in Java
    By Sheenas in forum Software Development
    Replies: 4
    Last Post: 26-02-2010, 10:52 PM
  4. Sending SOAP Request in java
    By samualres in forum Software Development
    Replies: 5
    Last Post: 09-02-2010, 06:55 PM
  5. PHP form and sending via email
    By Gyan Guru in forum Guides & Tutorials
    Replies: 3
    Last Post: 14-11-2008, 12:21 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,613,897.64852 seconds with 17 queries