html dsl form can not find action url
- Dominant language
- Kotlin
- Stars
- 14.5k
- Forks
- 1.3k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 49
Description
### Ktor Version
1.1.2
### Ktor Engine Used(client or server and name)
netty
### JVM Version, Operating System and Relevant Context
jvm 1.8
os windows 10
kotlin 1.3.20
### Feedback
I use html dsl create form, but it can not find the action url
this is code
**Application.kt**
``` kotlin
@KtorExperimentalLocationsAPI
@Location("/user")
class User {
@Location("/login")
data class UserLogin(val username: String, val password: String)
@Location("/register")
data class UserRegister(val username: String, val password: String)
}
fun main(args: Array): Unit = io.ktor.server.netty.EngineMain.main(args)
@KtorExperimentalLocationsAPI
@Suppress("unused") // Referenced in application.conf
@kotlin.jvm.JvmOverloads
fun Application.module(testing: Boolean = false) {
install(Locations)
routing {
user()
get("/") {
call.respondHtml {
head {
title {
+"Ktor 入门"
}
}
body {
a {
href = "/register"
+"注册"
}
form("/user/login", method = FormMethod.post, encType = FormEncType.multipartFormData) {
input {
type = InputType.text
name = "username"
}
br
input {
type = InputType.password
value = ""
name = "password"
}
br
input {
type = InputType.submit
value = "login"
}
}
}
}
}
get("/login") {
call.respond("success")
}
}
}
```
```kotlin
@KtorExperimentalLocationsAPI
fun Route.user() {
post {
call.respondText("登录成功")
}
post { user ->
run {
call.respondText("用户 ${user.username} ${user.password}")
}
}
}
```
in browers ,can not find the url

but i used the .http file , can get response

Contributor guide
Research direction
Start with Application.kt and the user() routing entry point, then reproduce the form submission in a browser and inspect the generated form HTML. Compare the browser request with the working .http request and trace how the HTML DSL builds the action URL. Done means the form reaches the User.UserLogin POST route as intended.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin
- Domain
- backend, web-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100