Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script>
- function getCustomerDetailsAjax(str) {
- str = $('#customerId').val();
- if (document.getElementById('customerId').value <= 0) {
- document.getElementById('firstName').value = " ";
- document.getElementById('telephone').value = " ";
- document.getElementById('vehicleMake').value = " ";
- document.getElementById('vehicleModel').value = " ";
- document.getElementById('vehicleColor').value = " ";
- } else {
- $.ajax({
- url: "GetCustomerDetails",
- type: 'POST',
- data: {customerId: str},
- success: function (data) {
- alert(data); //I want to get 2 servlet values and alert them here. How can I do that?
- }
- });
- }
- }
- </script>
- public class GetCustomerDetails extends HttpServlet {
- @Override
- protected void doPost(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- PrintWriter out=response.getWriter();
- int customerId = Integer.valueOf(request.getParameter("customerId"));
- try {
- Class.forName("com.mysql.jdbc.Driver");
- Connection con = DriverManager.getConnection("jdbc:mysql://localhost/Vehicle", "root", "");
- PreparedStatement ps = con.prepareStatement("SELECT fistname,telephone FROM customers WHERE customerid=?");
- ps.setInt(1, customerId);
- ResultSet result=ps.executeQuery();
- if(result.next()){
- out.print(result.getString("firstname")); //I want to send this value
- out.print(result.getString("telephone")); //and this value
- }
- } catch (ClassNotFoundException ex) {
- Logger.getLogger(GetCustomerDetails.class.getName()).log(Level.SEVERE, null, ex);
- } catch (SQLException ex) {
- Logger.getLogger(GetCustomerDetails.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- @Override
- public String getServletInfo() {
- return "Short description";
- }// </editor-fold>
- success: function (data) {
- alert(data); //I want to get 2 servlet values and alert them here. How can I do that?
- }
Add Comment
Please, Sign In to add comment