Community
Participate
Working Groups
It would be nice to have a default template code generated for Servlet. This will make the generated Servlet a little bit more useful, and much easier to showcase in demos. For example, here is one template that could be generated in doGet() and doPost(): protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.getOutputStream().print("Served at: " + request.getContextPath()); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); }
Good suggestion for enhancement. A patch is welcome. Triaging initially for WTP 3.7
Created attachment 251623 [details] Suggested patch
Created attachment 251624 [details] updated patch
Created attachment 251625 [details] Generated Servlet sreenshot
Created attachment 251651 [details] Generated Servlet sreenshot
(In reply to Daniel Azarov from comment #3) > Created attachment 251624 [details] > updated patch Hi Daniel, thank you for the patch. I have a couple of comments: 1. In order to contribute patches, you need a CLA. More information here: http://wiki.eclipse.org/CLA 2. In your patch, the doPost method calls directly doGet. But in the new servlet wizard, the user can select to not create the doGet methods. So, if the user only selects to create doPost, doPost would be calling the HttpServlet implementation of doGet. Not sure if we want that. 3. Why did you decide to use response.getOutputStream(), which according to the javadoc: "Returns a ServletOutputStream suitable for writing binary data in the response", instead of response.getWriter(), which seems more appropriate (from javadoc: Returns a PrintWriter object that can send character text to the client.) 4. Did you update manually the file ServletTemplate.java? Or did you let JET to update it based on the changes in servlet.javajet?
(In reply to Roberto Sanchez Herrera from comment #6) Hi Roberto, thank you for your comments > 1. In order to contribute patches, you need a CLA. More information here: > http://wiki.eclipse.org/CLA Done > 2. In your patch, the doPost method calls directly doGet. But in the new > servlet wizard, the user can select to not create the doGet methods. So, if > the user only selects to create doPost, doPost would be calling the > HttpServlet implementation of doGet. Not sure if we want that. I am going to test something like: <% if (model.shouldGenDoPost()) { %> protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { <% if (model.shouldGenDoGet()) { %> doGet(request, response); <% } %> } <% } %> > > 3. Why did you decide to use response.getOutputStream(), which according to > the javadoc: "Returns a ServletOutputStream suitable for writing binary data > in the response", instead of response.getWriter(), which seems more > appropriate (from javadoc: Returns a PrintWriter object that can send > character text to the client.) How about: response.getWriter().append("Served at: ").append(request.getContextPath()); > 4. Did you update manually the file ServletTemplate.java? Or did you let JET > to update it based on the changes in servlet.javajet? I did it manually. Now trying to figure out how JET works...
JET Builder was switched off for org.eclipse.jst.j2ee.web project when I turned it on - it created new ServletTemplate.java But copyright header is gone and all NON-NLS comments. Are there any setting to fix it? or should I add them back manually? Or should I just get two new lines for new ServletTemplate.java? Thank you.
Created attachment 251670 [details] updated patch
Created attachment 251671 [details] Generated Servlet sreenshot
Created attachment 251672 [details] Servlet with no doGet method
Created attachment 251673 [details] Servlet with no doPost method
(In reply to Daniel Azarov from comment #8) > JET Builder was switched off for org.eclipse.jst.j2ee.web project > > when I turned it on - it created new ServletTemplate.java > > But copyright header is gone and all NON-NLS comments. > Are there any setting to fix it? or should I add them back manually? > > Or should I just get two new lines for new ServletTemplate.java? > > Thank you. Usually when we update code generated by JET, we make the changes in the .javajet file, enable the JET builder, and once JET generates what we want, we disable the builder, and edit what JET generated, to fix the copyright headers and add the NON-NLS comments manually.
(In reply to Roberto Sanchez Herrera from comment #13) > (In reply to Daniel Azarov from comment #8) > > JET Builder was switched off for org.eclipse.jst.j2ee.web project > > > > when I turned it on - it created new ServletTemplate.java > > > > But copyright header is gone and all NON-NLS comments. > > Are there any setting to fix it? or should I add them back manually? > > > > Or should I just get two new lines for new ServletTemplate.java? > > > > Thank you. > > Usually when we update code generated by JET, we make the changes in the > .javajet file, enable the JET builder, and once JET generates what we want, > we disable the builder, and edit what JET generated, to fix the copyright > headers and add the NON-NLS comments manually. Thank you. That's exactly what I did for last updated patch. :)
The patch works fine, but I'd exclude the addition of the file org.eclipse.emf.codegen.JETBuilder.launch and the changes in org.eclipse.jdt.core.prefs. Requesting review from Chuck.
Created attachment 251759 [details] updated patch Patch updated, org.eclipse.emf.codegen.JETBuilder.launch and the changes in org.eclipse.jdt.core.prefs excluded.
Committed to master for WTP 3.7 (http://git.eclipse.org/c/jeetools/webtools.javaee.git/commit/?id=0a7fa296ed81df94826f44e5cb57f0435cc23979) I incremented the plugin version as part of the change. Resolving.