开发者

Editing a .jsp file from an App Engine project in Eclipse

I am currently creating m开发者_JAVA百科y first project using Google App Engine in Eclipse. For my main page it seems I can create either:

  • a servlet (class that extends HttpServlet)
  • or I can create a jsp file.

Is there a way in Eclipse to make it aware of the java code in a jsp file and to use all the IDE goodies such as colored text, inline documentation, auto-complete? And is there a way to auto build and validate the code in a jsp or it can only show the errors on the first load of the web app?

It seems to be a lot easier to develop in a servlet class than in a jsp file. Or did I miss something?


Eclipse tries to validate the markup and autocomplete it in the JSP files if you have the WTP (Web Tools Platform) installed. But even that sometimes doesn't work well because it's difficult to parse HTML containing JSP tags, Javascript, etc.

Regarding the Java code : it's bad practice to have Java code in scriptlets in JSPs. You should only use JSPs for pure presentation logic, and use JSTL and custom tags for that. The Java code should be in a servlet or action invoked before the JSP. Use an MVC framework (Stripes, Struts, Spring MVC, etc.) to separate your Java code from your JSP code. I've used Stripes on app engine with success and pleasure.

To make sure your JSPs are valid, you can be helped by Eclipse, but you should also deploy your webapp (on the local server) and run tests to make sure every JSP compiles and runs correctly. You can automate these tests with HtmlUnit or Selenium.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜