Yes, given a type system than is expressive and powerful enough, this is indeed possible.
Ur/Web, for example, is a web application framework written in the Ur programming language, in which several interesting properties are guaranteed by the type system:
- there cannot be dead links (within the application)
- it is impossible to generate invalid HTML
- it is impossible to have XSS attacks
- SQL injection is impossible
- form fields always have a corresponding server-side handler
- AJAX calls always have a corresponding server-side handler
- the types of client-side form fields, server-side handlers and database tables match up
- ... a lot more ...
Adam Chlipala, the author of Ur and Ur/Web gave a talk about it at the Emerging Languages Camp 2010.
There are also some web frameworks in Haskell, OCaml and Scala that (try to) do (some of) that. Their type systems are powerful enough to guarantee at least some of those properties. There are type-safe embeddings of SQL into Haskell, for example, or an HTML templating language in OCaml that doesn't allow the user to generate invalid HTML.