Simple Ajax application of struts2 + jquery (Memo)

Source: Internet
Author: User
<% @ Page Language = "Java" Import = "Java. util. *" pageencoding = "UTF-8" %> <! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en"> <HTML> 

JSON can be used to directly read the attribute values in the action instead of the out. Print (...) in the servlet (...)

Package COM. ajax. action; import COM. opensymphony. xwork2.actionsupport; public class ajaxaction extends actionsupport {private string username; // to reduce the card surface, add the get, Set Method private string password; private string MSG; Public String execute () {If (username. equals ("admin") & password. equals ("admin") {MSG = "Hello, login successfully";} else {MSG = "Login fail" ;}return "success ";}}

Then, in the XML file, set the type of the result to JSON, which corresponds to the ype in the previous. Post (), and inherit the JSON-Default

<package name="ajax" namespace="/" extends="json-default"><action name="ajax" class="com.ajax.action.AjaxAction"><result type="json"></result></action></package>
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.