Haskell Web框架 [英] Haskell Web Framework

查看:96
本文介绍了Haskell Web框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用haskell创建简单的Web应用程序.首先,我在前面使用了Snap,可以运行该应用程序,但是我想向该应用程序添加用户输入.
我找不到将用户输入参数输入到函数的方法.我该怎么办?

I'm creating simple web application using haskell. First I used Snap in front and I was able to run the application, but I want to add user input to the application.
I couldn't find a way to get user input parameters to the function. How might I do that?

另外,我还使用了Happstack框架,无法导入"Happstack.Server".我使用cabal安装配置Happstack.它已成功安装,但是当我尝试导入"Happstack.Server"时,它给了我一个错误:

Other thing, I also used Happstack framework, I can not import "Happstack.Server". I use cabal installation configure Happstack. It was successfully installed, but when I try to import to "Happstack.Server", it gives me an error:

<no location info>:
Could not find module `Happstack.Server':
  it is not a module in the current program, or in any known package.

如果我使用ghc --make HelloWorld.hs -v运行程序,则会得到:

If I run my program using ghc --make HelloWorld.hs -v, I get:

Glasgow Haskell Compiler, Version 6.12.1, for Haskell 98, stage 2 booted by GHC version 6.12.1
Using binary package database: /usr/lib/ghc-6.12.1/package.conf.d/package.cache
Using binary package database: /home/udeshika/.ghc/i386-linux-6.12.1/package.conf.d/package.cache
package happstack-6.0.0-0f0c2507d590ebd01e8601c8667ec809 is unusable due to missing or recursive dependencies:
  happstack-ixset-6.0.0-4e1b5476a551c4501c5734b22e0b280d happstack-server-6.0.3-6d71e7bb09489130538fb851a694b927 happstack-state-6.0.0-0e753e61d7092b6a5139e473113877a1 happstack-util-6.0.0-4156bd1331b7a0d62e0087101c9eba1c
package happstack-ixset-6.0.0-4e1b5476a551c4501c5734b22e0b280d is unusable due to missing or recursive dependencies:
  happstack-util-6.0.0-4156bd1331b7a0d62e0087101c9eba1c
package happstack-server-6.0.3-6d71e7bb09489130538fb851a694b927 is unusable due to missing or recursive dependencies:
  happstack-util-6.0.0-4156bd1331b7a0d62e0087101c9eba1c hslogger-1.1.4-90c801c802eec92e4e6a6f83d24d58d9 network-2.2.1.7-72dad7eb07ee7a683982f7475b8a449f network-bytestring-0.1.3.4-937fd511949a2d5ef21e86ec5306c791 sendfile-0.7.3-137cf51cc81a277d724637a7cd1e6b09
package happstack-state-6.0.0-0e753e61d7092b6a5139e473113877a1 is unusable due to missing or recursive dependencies:
  happstack-util-6.0.0-4156bd1331b7a0d62e0087101c9eba1c hslogger-1.1.4-90c801c802eec92e4e6a6f83d24d58d9
package happstack-util-6.0.0-4156bd1331b7a0d62e0087101c9eba1c is unusable due to missing or recursive dependencies:
  hslogger-1.1.4-90c801c802eec92e4e6a6f83d24d58d9 network-2.2.1.7-72dad7eb07ee7a683982f7475b8a449f
package hslogger-1.1.4-90c801c802eec92e4e6a6f83d24d58d9 is unusable due to missing or recursive dependencies:
...................

推荐答案

Snap的 getParam 函数允许您获取用户指定的HTTP请求参数.这些可以出现在表单提交的帖子正文中,也可以来自查询字符串.例如,考虑以下代码:

Snap's getParam function allows you to get HTTP request parameters specified by the user. These can come in the post body of a form submission or from the query string. For example, consider the following code:

site = dir "mypage" pageHandler
pageHandler = do
    val <- getParam "foo"
    writeBS $ maybe "no value" id val

如果我请求网址"myapp.com/mypage?foo=bar",那么我将看到"bar"作为响应.如果我省略?foo = bar"部分,那么它将返回无值".

If I request the url "myapp.com/mypage?foo=bar", then I will see "bar" as the response. If I leave off the "?foo=bar" part, then it will return "no value".

这篇关于Haskell Web框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆