⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 servlet2.c

📁 picoos源码。The RTOS and the TCP/IP stack will be built automatically.
💻 C
字号:
/*
 *  Copyright (c) 2004, Dennis Kuschel.
 *  All rights reserved. 
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions
 *  are met:
 *
 *   1. Redistributions of source code must retain the above copyright
 *      notice, this list of conditions and the following disclaimer.
 *   2. Redistributions in binary form must reproduce the above copyright
 *      notice, this list of conditions and the following disclaimer in the
 *      documentation and/or other materials provided with the distribution.
 *   3. The name of the author may not be used to endorse or promote
 *      products derived from this software without specific prior written
 *      permission. 
 *
 *  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
 *  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 *  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 *  ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
 *  INDIRECT,  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 *  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 *  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 *  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 *  OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */

/**
 * @file    servlet2.c
 * @author  Dennis Kuschel
 * @brief   Simple counter servlet.
 *
 * This software is from http://mycpu.mikrocontroller.net.
 * Please send questions and bug reports to dennis_k@freenet.de.
 */

#include "../src/sys.h"
#include "../src/httpd.h"


/* function prototypes */
sint_t  my_counter_servlet(SERVLET_t so);


/*
 *  This is a very simple servlet.
 *  It provides a html page with a counter on it -
 *  when the hyperlink on the page is pressed, the counter
 *  is incremented by one. The new counter state is passed
 *  to the servlet by a parameter attached to the URI.
 */

sint_t  my_counter_servlet(SERVLET_t so)
{
  sint_t status;
  char *p;
  u32_t c;

  /* read parameter (counter state) from URI */
  p = hsl_getParameterByName(so, "c");
  c = 0;
  if (p != NULL)
    sscanf(p, "%u", &c);

  /* print counter to console window (only for demonstration) */
  printf("c = %u\n", c);

  /* create html header */
  hsl_printf(so, "<html><head><title>My Counter Servlet</title></head><body>\n");
  hsl_printf(so, "<a href=\"index.html\">Index</a><br>");

  /* insert a message (state of the counter) into the html page */
  hsl_printf(so, "<br><br><center><h1>Counter = %u</h1><br><br>\n", c);

  /* Insert a hyperlink into the html page.
     The hyperlink links to this servlet and passes a new counter value */
  status = hsl_linkCreate(so, NULL, 0);
  if (status == 0)  
    status = hsl_linkAddNumberVal(so, "c", c+1);
  if (status == 0)
    status = hsl_linkInsert(so, "increment counter");
  if (status != 0)
    hsl_printf(so, "[ failed to insert link here!]"); /* just for debugging */
  hsl_printf(so, "<br>\n</center>\n");

  /* create html footer */
  hsl_printf(so,"</body></html>\n");
  
  return SLERR_OK;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -