ExtJs reads servlet to send data

Source: Internet
Author: User

EXTJS

Application. js

Ext. onReady (function () {// var data = [{// name: 'tang bohu ', // age: 25, // sex: 'male '//}, {// name: 'chu Liuxiang ', // age: 24, // sex: 'female' //}]; var ds = new Ext. data. jsonStore ({proxy: new Ext. data. httpProxy ({url: 'datalist' // relative path}), root: '', fields: [{name: 'name'}, {name: 'age '}, {name: 'sex'}]}); // ds. loadData (data); var grid = new Ext. grid. gridPanel ({viewConfig: {forceFit: true}, store: ds, columns: [{header: 'name', dataIndex: 'name'}, {header: 'age ', dataIndex: 'age'}, {header: 'birthdate ', dataIndex: 'sex'}]}); var win = new Ext. window ({title: 'httpproxy', width: 400, height: 300, layout: 'fit ', items: grid}); ds. load (); win. show ();});



Servlet

DataList. java

Package com. ext. servlet; import java. io. IOException; import java. io. outputStream; import java. io. printStream; import java. io. printWriter; import javax. servlet. servletException; import javax. servlet. http. httpServlet; import javax. servlet. http. httpServletRequest; import javax. servlet. http. httpServletResponse; import net. sf. json. JSONArray; import net. sf. json. JSONObject; import org. apache. jasper. tagplugins. jstl. core. out;/*** Servlet implementation class dataList */public class dataList extends HttpServlet {private static final long serialVersionUID = 1L;/*** @ see HttpServlet # HttpServlet () */public dataList () {super (); // TODO Auto-generated constructor stub}/*** @ see HttpServlet # doGet (HttpServletRequest request, HttpServletResponse response) */protected void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// TODO Auto-generated method stub // response. setContentType ("text/html"); response. setCharacterEncoding ("UTF-8"); String _ str = "[{name: 'tang bohu ', age: 25, sex: 'male'}, {name: 'chu Liuxiang', age: 24, sex: 'female '}] "; // _ str =" [{name: 'tang bohu', age: 25, sex: 'male'}, {name: 'chu Liuxiang ', age: 24, sex: 'female'}]; "; response. getWriter (). write (_ str); // request. setAttribute ("ooo", _ str); // request. getRequestDispatcher ("datawrite. jsp "). forward (request, response);}/*** @ see HttpServlet # doPost (HttpServletRequest request, response) */protected void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {}}
Web. xml

  
     
      
  
   dataList
      
  
   dataList
      
  
   com.ext.servlet.dataList
    
   
     
  
   dataList
      
  
   /dataList
    
   
 

Foreground test path

Http: // localhost: 8080/ExtJsApplication/index.html





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.