Getting started with jeewx-api.jar, servletapi. jar

Source: Internet
Author: User

Getting started with jeewx-api.jar, servletapi. jar

Jeewx-api.jar getting started
Attachment:
Http://download.csdn.net/detail/zxl78585/8549027
1. Apply for a test account on the official website.
Address: http://mp.weixin.qq.com/debug/cgi-bin/sandboxinfo? Action = showinfo & amp; t = sandbox/index
Click log on and use your own scan.



2. Configure Tomcat in Eclipse
In window-& gt; preferences-& gt; server-& gt; runtime environments

2. Open Eclipse and create a web project

In eclipse, the default jdk is 1.5. Here, we need to change jdk to 1.7. : Right-click the project, select build path, select configure build path, select jdk1.5 in libraries, click edit, and modify it to 1.7.
3. Import the jar package
Jeecg-the api package depends on the other nine packages and is imported together

Select these packages, right-click build path, and click add to build path. In this way, all the jar files are added to the project.
4. Create a form page
Create an index. jsp page in the WebContent directory

Html code
  1. <Body>
  2. <Form action = "ApiDemo" method = "post">
  3. <Table>
  4. <Tr>
  5. <Td> appId </td>
  6. <Td> <input type = "text" id = "appId" name = "appId"/> </td>
  7. </Tr>
  8. <Tr>
  9. <Td> appSecret </td>
  10. <Td> <input type = "text" id = "appSecret" name = "appSecret"/> </td>
  11. </Tr>
  12. <Tr>
  13. <Td colspan = "2" align = "center"> <input type = "submit" value = "submit"/> </td>
  14. </Tr>
  15. </Table>
  16. </Form>
  17. <%
  18. /* Obtain the content uploaded from the background */
  19. String data = (String) session. getAttribute ("data ");
  20. %>
  21. <% = Data %>
  22. </Body>

 

5. Create a servlet
An error is reported when a new servlet is created. This error is generally caused by the lack of jar. At this time, we do not need to import the tomcat package from external sources. In the build path, add the tomcat package to add the method.
Right-click a project
Build path-& gt; configure build path-& gt; libraries-& gt; add library-& gt; server runtime

6. In the doPost method, write:

 

 

Java code
  1. // Set the encoding format
  2. Request. setCharacterEncoding ("UTF-8 ");
  3. // Obtain parameters from the page
  4. String appid = request. getParameter ("appId ");
  5. String appsecret = request. getParameter ("appSecret ");
  6. // Determine whether appid and appsecret are empty
  7. If (StringUtils. isNotBlank (appid) & StringUtils. isNotBlank (appsecret )){
  8. // Token
  9. String token = null;
  10. // Obtain the token
  11. Try {
  12. // Call the method in jeewx-api to obtain the token
  13. Token = Your tokenapi. getAccessToken (appid, appsecret );
  14. } Catch (WexinReqException e ){
  15. }
  16. List <Wxuser> users = null;
  17. // Get all users through token
  18. Try {
  19. Users = login userapi. getAllWxuser (token, null );
  20. } Catch (WexinReqException e ){
  21. }
  22. StringBuffer result = new StringBuffer ();
  23. // Concatenate the result into a string
  24. For (Wxuser wxuser: users ){
  25. Result. append ("Country:" + wxuser. getCountry () + "City:" + wxuser. getCity () + "Gender:" + wxuser. getSex () + "<br/> ");
  26. }
  27. // Put the result into the session
  28. Request. getSession (). setAttribute ("data", result. toString ());
  29. // Jump to the previous page
  30. Response. sendRedirect ("index. jsp ");
  31. }


7. In the web. xml file

Xml Code
  1. <? Xml version = "1.0" encoding = "UTF-8"?>
  2. <Web-app xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns = "http://java.sun.com/xml/ns/javaee" xsi: schemaLocation = "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id = "WebApp_ID" version = "2.5">
  3. <Display-name> apiDemo </display-name>
  4. <Welcome-file-list>
  5. <Welcome-file> index.html </welcome-file>
  6. <Welcome-file> index.htm </welcome-file>
  7. <Welcome-file> index. jsp </welcome-file>
  8. <Welcome-file> default.html </welcome-file>
  9. <Welcome-file> default.htm </welcome-file>
  10. <Welcome-file> default. jsp </welcome-file>
  11. </Welcome-file-list>
  12. <Servlet>
  13. <Description> </description>
  14. <Display-name> ApiDemo </display-name>
  15. <Servlet-name> ApiDemo </servlet-name>
  16. <Servlet-class> apiDemo. userServiceTest. ApiDemo </servlet-class>
  17. </Servlet>
  18. <Servlet-mapping>
  19. <Servlet-name> ApiDemo </servlet-name>
  20. <Url-pattern>/ApiDemo </url-pattern>
  21. </Servlet-mapping>
  22. </Web-app>

 
8. Run the tomcat server
Page:

Enter appId and appSecret in it and click Submit. The corresponding results will be returned below:

 

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.