将服务的响应发送到html表单

时间:2014-08-21 06:58:24

标签: html web-services

我使用html表单向webservice提交某些值,如下所示:

<form action="http://host-address:8080/Rest/rest/service" method="POST" id = "form">
<label for="username">Username:</label> <input type="text" name="username" id="username"> 
<label for="password">Password:</label> <input type="password" name="password" id="password">
<a href="javascript:submitForm();" data-transition="slide" class="ui-btn ui-btn-inline ui-mini">Log In</a>
</form>

该服务只不过是从表单中获取数据并插入数据库的实现。

@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public void createMessage(@FormParam("username") String username,
@FormParam("password") String password){

try {
    Class.forName("com.mysql.jdbc.Driver");
    Connection conn = null;
    conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/jqmobile","root","");

    Statement stmnt = null;

     stmnt = conn.createStatement();

     stmnt.executeUpdate("insert into userdetails values ('" + username +"','"+ password +"')");


   }

 catch (Exception ex) {

     System.out.println("SQLException: " + ex.getMessage());
        System.out.println("SQLState: " + ((SQLException) ex).getSQLState());
        System.out.println("VendorError: " + ((SQLException) ex).getErrorCode());
 }
 }

现在,如果我想在html端显示成功或失败消息,则根据服务是否已成功插入数据库。我该怎么做?

一旦db事务完成,服务应该向html客户端发送响应。

0 个答案:

没有答案