通过ajax请求将数据发送到servlet时出错(App Engine)

时间:2013-10-23 19:10:42

标签: jquery ajax google-app-engine

我正在尝试使用jQuery Ajax请求将表单数据发送到servlet,并且它一直都会失败。

HTML表格:

<div>
<p id="response"></p>
</div>

<form id="theForm">
    <table >
            <tr><td><label for="firstname">First name:</label></td><td><input type="text" name="firstname" required></td></tr>
            <tr><td><label for="lastname">Last name:</label></td><td><input type="text" name="lastname" required></td></tr>
            <tr><td><label for="username">Username:</label></td><td><input type="text" name="username" required></td></tr>
            <tr><td><label for="password">Password:</label></td><td><input type="password" name="password" required></td></tr>
            <tr><td><label for="phoneNumber">Phone number:</label></td><td><input type="tel" name="phoneNumber" required></td></tr>
            <tr><td><label for="email">Email address:</label></td><td><input type="email" name="email" required></td></tr>
            <tr><td><label for="area">Area:</label></td><td><select name="area">
                <option value = "scotland">Scotland</option>
                <option value = "North West">North West</option>
                <option value = "North East">North East</option>
                <option value = "Wales">Wales</option>
                <option value = "Midlands">Midlands</option>
                <option value = "Eastern">Eastern</option>
                <option value = "South West">South West</option>
                <option value = "Southern">Southern</option>
                <option value = "South East">South East</option>
            </select></td></tr>
            <tr><td colspan="2"><input type="submit" name="sbt"></td></tr>
    </table>   
</form>

SCRIPT:

$(document).ready(function(){

$('#theForm').submit(function(){

    var formData = $(this).serialize();
    $.ajax
    (
        {
            url:'/uniprojectgae',
            data:formData,
            type:'get',
            cache:false,
            success:function processResponse(data) {    
                $('#response').text(data);
            },
            error:function processResponse(data) {  
                $('#response').text('Error');
            }
        }
    );
});

     });

SERVLET(现在只发送'Success'消息):

    public class UniProjectGAEServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws IOException, ServletException {

    resp.getWriter().write("Success");
    }

据我所知,当我发送数据时,带有查询字符串的地址会出现如下:

http://localhost:8888/?      firstname=John&lastname=Rock&username=johnrock&password=pass&phoneNumber=045588564556&email=job%40gmail.com&area=scotland&sbt=Submit

它没有斜杠和问号之间的servlet名称?

0 个答案:

没有答案