You use a structured framework that has some separation of concerns (typically Model-View-Controller or some variant). In Java-world, some examples are Struts, Spring MVC, and Play, all of which can be used to write high-quality software for real-world applications. JSP might even be involved in the view/presentation layer.
There are also MVC frameworks for PHP. The most popular, though, are those for scripting languages like Ruby and Python, namely Rails and Django.
What you shouldn't be doing is interleaving data access, business logic, and presentation all in one file, which is what straight PHP and JSP usually consist of. This is called "spaghetti code" and it's been widely regarded as a really terrible practice for around 10 years.
You can do client-side apps in Javascript that fetch JSON or XML from the server, but you want to be using a framework with some structure to serve the data, still not just straight PHP or JSP.
> What you shouldn't be doing is interleaving data access, business logic, and presentation all in one file, which is what straight PHP and JSP usually consist of. This is called "spaghetti code" and it's been widely regarded as a really terrible practice for around 10 years.
"spaghetti code" actually has a much broader definition than that particular kind of lack of structure (though I agree that that example might be viewed as a fairly modern example of "spaghetti code") and has been considered a terrible practice for much longer than PHP, JSP, or even the web itself has existed. [1]
There are also MVC frameworks for PHP. The most popular, though, are those for scripting languages like Ruby and Python, namely Rails and Django.
What you shouldn't be doing is interleaving data access, business logic, and presentation all in one file, which is what straight PHP and JSP usually consist of. This is called "spaghetti code" and it's been widely regarded as a really terrible practice for around 10 years.
You can do client-side apps in Javascript that fetch JSON or XML from the server, but you want to be using a framework with some structure to serve the data, still not just straight PHP or JSP.