AJAX with JSP and Servlet (CODE), ajaxservlet

Source: Internet
Author: User

AJAX with JSP and Servlet (CODE), ajaxservlet

You are welcome to reprint it in any form, but be sure to indicate the source.

This chapter is about FQ for YouTube (click to learn from the video)

 

For more information about server configurations, see my other articles. Add comments

Structure

 

 1     <body> 2         <fieldset> 3             <ledend>Demo 1</ledend> 4             <form> 5                 Name <input type="text" id="fullname"> 6                 <input type="button" value="Hello" id="bttHello"> 7                 <br> 8                 <span id="result1"></span> 9             </form>10         </fieldset>11         12         <fieldset>13             <ledend>Demo 2</ledend>14             <form>15                 Number 1<input type="text" id="number1"><br>16                 Number 2<input type="text" id="number2"><br>17                 Result<span id="result2"></span><br>18                 <input type="button" value="Sum" id="bttSum">19                 20                 21             </form>22         </fieldset>23 24     </body>
Body section
 1     Ajax Section
 1     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 2         // TODO Auto-generated method stub 3         response.setContentType("text/plain"); 4         PrintWriter out = response.getWriter(); 5         String action = request.getParameter("action"); 6         if(action.equals("demo1")){ 7             String fullname = request.getParameter("fullname");     8             out.print("Hello"+fullname); 9         }10         else if(action.equals("demo2")){11             int number1 = Integer.parseInt(request.getParameter("number1"));12             int number2 = Integer.parseInt(request.getParameter("number2"));13             out.println(number1+number2);14         }15         16     }
Servlet Section

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.