Scala-liftweb框架
我有两个复选框,在提交时我想让用户下载两个不同的文件,我该怎么做?我需要帮助,因为我无法获得任何有关这方面的在线资料。我不熟悉这个框架 这就是我到目前为止所尝试的Scala-liftweb框架,scala,checkbox,lift,Scala,Checkbox,Lift,我有两个复选框,在提交时我想让用户下载两个不同的文件,我该怎么做?我需要帮助,因为我无法获得任何有关这方面的在线资料。我不熟悉这个框架 这就是我到目前为止所尝试的 def render = { def onSubmit1() : LiftResponse = { val userInput1 = S.param("getit").openOr("") val userInput2 = S.param("getit2").openOr("") val che
def render = {
def onSubmit1() : LiftResponse = {
val userInput1 = S.param("getit").openOr("")
val userInput2 = S.param("getit2").openOr("")
val checkbox1 = S.param("yes").openOr("")
val checkbox2 = S.param("yes").openOr("")
val fileToDownload = funFile(as, art, top)
val fileName = "My File"
if (fileToDownload.equals()) {
return S.redirectTo("/Somewhere")
} else {
InMemoryResponse(
fileToDownload.mkString("\n").getBytes("UTF-8"),
"Content-Type" -> "text/plain; charset=utf8" ::
"Content-Disposition" -> s"attachment; filename=$fileName" :: Nil,
cookies = Nil, code = 200)
}
"#submitButton" #> SHtml.onSubmitUnit(onSubmit1)
我找到了一种方法,就是使用这个函数压缩这两个文件 ,
我找到了一种方法,就是使用这个函数压缩这两个文件 ,
我想你必须通过javascript来完成我想你必须通过javascript来完成
if (checkbox1.getOrElse("") == "checked" && checkbox2.getOrElse("") == "checked") {
val checkboxIterable1: Iterable[String] = filegetter1
val checkboxFile1 = new File("checkboxFile1.csv")
using(new FileWriter(checkboxFile1))(writer =>
fileGetter1.foreach { d =>
writer.write(d)
})
fileGetter1
val checkboxIterable2: Iterable[String] = fileGetter2
val checkboxFile2 = new File("checkboxFile2.csv")
using(new FileWriter(checkboxFile2))(writer =>
fileGetter2.foreach { d =>
writer.write(d)
})
fileGetter2
val zipFile = zip("Zipped file", List("checkboxFile1.csv", "checkboxFile2.csv"))
val zipFileName = "Zipped file"
val zipToBArray = new BufferedInputStream(new FileInputStream(zipFileName))
val getByteArray = Stream.continually(zipToBArray.read).takeWhile(-1 !=).map(_.toByte).toArray
InMemoryResponse(
getByteArray,
"Content-Type" -> "application/zip; charset=utf8" ::
"Content-Disposition" -> s"attachment; filename=file.zip" :: Nil,
cookies = Nil, code = 200)
}