关于jsp源代码
我开发了一个非常大的 Web 应用程序。如果我需要在 JSP 页面中进行任何更改,则需要花费太多时间来查找 JSP 页面、链接、操作等。
那么,是否有任何工具或技术可以让我直接访问 JSP 页面?该特定 JSP 页面的代码?
我认为“查看来源”是不同的。它只显示该 JSP 的源代码?
I have developed a very large Web application. If there is any change I need to make in a JSP page, it takes too much time to find that JSP page, link, action, etc.
So, are there any tools or are there any techniques through which I can directly get to the code of that particular JSP page?
I think "View Sources" is different. it shows only source of that JSP?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您是否尝试过 NetBeans 或 Eclipse 或 MyEclipse 或任何其他 IDE?
您可以使用此工具的快捷方式在您的应用程序中查找适当的代码。
它们可以帮助您更快地在应用程序中找到 JSP 页面。
Have you tried NetBeans or Eclipse or MyEclipse or any other IDE?
You can use shortcuts of this tools to find appropriate code in your application.
They may help you in finding your JSP page in your application faster.
技术——您可能可以使用适当的设计模式来分段您的代码,使每个 jsp 页面代表“操作”,例如 addFriendAction.jsp。这样做的优点是找到合适的页面名称会更容易,因为您只需引用相应的操作即可。将此与 JSP 页面进行比较,在 JSP 页面中将多个操作合并到同一页面中。这是一个示例(我假设您正在根据 MVC 模式使用 servlet 和 jsp 页面)。例如,使用命令模式将 Web 应用程序构建为操作(请参阅代码示例 4.8- http://java.sun.com/blueprints/guidelines/designing_enterprise_applications_2e/web-tier/web-tier5.html)
添加到上面,让我分享一个我最近做的项目,其中使用了这种模式的。下面是我的 servlet 类,
您可以看到每个操作都是在主 servlet 中通过将其分派到较小的 servlet 来处理的。 因此,如果单击 CreateUserAction,该操作将由 CreateUserAction.java servlet 处理,然后该 servlet 将输出重定向到 CreateUserAction.jsp。这样,使用适当的模式可以轻松地找到相应的 JSP 页面,从而对代码进行分段。这就是我在这里试图提出的要点 - 使用模式!
模板 - 您可以跨页面使用 JSP 模板,这样您只需要修改模板即可实现跨 JSP 页面的常见更改(请参阅- http://java.sun.com/developer/technicalArticles/javaserverpages/jsp_templates/< /a>)
一个相当幼稚的方法是使用 IDE 快捷方式。
techniques-- you could probably use an appropriate design pattern to fragment your code in such a way that each jsp page represents "actions" e.g. addFriendAction.jsp. the advantage here is that finding the appropriate page name would be easier as you just have to refer to corresponding action. compare this with having JSP pages where you incorporate multiple actions in the same page. heres an example (Im assuming you're using servlets along with the jsp pages in accordance with the MVC pattern). e.g. using the command pattern to structure your web app into actions (refer Code Example 4.8- http://java.sun.com/blueprints/guidelines/designing_enterprise_applications_2e/web-tier/web-tier5.html)
adding to above, let me share a recent project i did which made use of this pattern. below is my servlet class
you can see that each action is handled in the main servlet by dispatching it to smaller servlets. so if you click on CreateUserAction, this action is handled by a CreateUserAction.java servlet, which then redirects the output to CreateUserAction.jsp. this way, using an appropriate pattern fragments your code in such a way that finding the respective JSP page is done easily. that is the point i'm trying to make here- use patterns!
templates-- you could make use of JSP templates across pages so that you only need to modify the template to effect common changes across the JSP pages (refer- http://java.sun.com/developer/technicalArticles/javaserverpages/jsp_templates/)
a rather naive way would be use IDE shortcuts.
生成一个 HTML 注释,标识每个代码部分的源代码到最终输出,可能是为了响应“调试”类型的查询参数。然后使用“查看源代码”查看代码,您应该能够很容易地找出它的来源。
将这些注释添加到代码中需要花费一些时间,但是随着时间的推移,您可以在修改内容时逐步完成。
Generate an HTML comment identifying the source of each section of code right into the final output, possibly in response to a "debug" type query parameter. Then eyeball the code with "view source" and you should be able to figure out where it came from quite easily.
It will take time to add these comments to your code, but you can do it piecemeal over time as you modify things.
我认为这更符合编码标准和最佳实践。
I think this is more towards coding standards and best practices here.
(如果您需要一些,请考虑重新设计约定)。
(if you need some, think about redesigning the convention).