关于jsp源代码

发布于 2024-10-10 16:56:51 字数 165 浏览 1 评论 0原文

我开发了一个非常大的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

握住你手 2024-10-17 16:56:51

您是否尝试过 NetBeansEclipseMyEclipse 或任何其他 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.

我要还你自由 2024-10-17 16:56:51

技术——您可能可以使用适当的设计模式来分段您的代码,使每个 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 类,

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package servlets;

import beans.SeekerCustomer;
import java.io.*;
import java.util.HashMap;
import javax.servlet.*;
import javax.servlet.http.*;
/**
 *
 * @author Dhruv
 */

//servlet class acts as controller by delegating
//operations to the respective Action concrete subclass
public class ControllerServlet extends HttpServlet {

    //stores all the possible operation names
    //and operation objects for quick access
    private HashMap actions;

    @Override
    public void init() throws ServletException {
        actions = new HashMap();

        //all the various operations are stored in the hashmap
        CreateUserAction cua = new CreateUserAction(new SeekerCustomer());
        actions.put(cua.getName(), cua);
        ValidateUserAction vua = new ValidateUserAction(new SeekerCustomer());
        actions.put(vua.getName(), vua);
        ListNonFriendsAction lnfa = new ListNonFriendsAction(new SeekerCustomer());
        actions.put(lnfa.getName(), lnfa);
        AddFriendAction afa = new AddFriendAction(new SeekerCustomer());
        actions.put(afa.getName(), afa);
        ConfirmFriendReqAction cfra = new ConfirmFriendReqAction(new SeekerCustomer());
        actions.put(cfra.getName(),cfra);
        DeclineFriendReqAction dfra = new DeclineFriendReqAction(new SeekerCustomer());
        actions.put(dfra.getName(),dfra);
        AddImageAction aia = new AddImageAction(new SeekerCustomer());
        actions.put(aia.getName(),aia);
        ViewImageAction via = new ViewImageAction(new SeekerCustomer());
        actions.put(via.getName(),via);
        ViewAllImagesAction vaia = new ViewAllImagesAction(new SeekerCustomer());
        actions.put(vaia.getName(),vaia);
        AddTagAction ata = new AddTagAction(new SeekerCustomer());
        actions.put(ata.getName(),ata);
        ViewTagAction vta = new ViewTagAction(new SeekerCustomer());
        actions.put(vta.getName(),vta);
        ViewAllTagsAction vata = new ViewAllTagsAction(new SeekerCustomer());
        actions.put(vata.getName(),vata);
        ViewProfileAction vpa = new ViewProfileAction(new SeekerCustomer());
        actions.put(vpa.getName(),vpa);
        EditAccountAction epa = new EditAccountAction(new SeekerCustomer());
        actions.put(epa.getName(),epa);
        ViewOthersImageAction voia = new ViewOthersImageAction(new SeekerCustomer());
        actions.put(voia.getName(), voia);
        AddOthersTagAction aota = new AddOthersTagAction(new SeekerCustomer());
        actions.put(aota.getName(),aota);
        LogoutAction loa = new LogoutAction(new SeekerCustomer());
        actions.put(loa.getName(), loa);
        ToptagsAction tts = new ToptagsAction(new SeekerCustomer());
        actions.put(tts.getName(), tts);
        UpdateAccountAction uaa = new UpdateAccountAction(new SeekerCustomer());
        actions.put(uaa.getName(), uaa);
        ViewAllFriendsAction vafa = new ViewAllFriendsAction(new SeekerCustomer());
        actions.put(vafa.getName(), vafa);
        ReturnHomeAction rha = new ReturnHomeAction(new SeekerCustomer());
        actions.put(rha.getName(),rha);
    }

    public void processRequest(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {

        //identify the operation from the URL
        String op = getOperation(req.getRequestURL());
        //find and execute corresponding Action
        Action action = (Action)actions.get(op);
        Object result = null;
        try {
            //maintain the session between requests
            result = action.perform(req, resp);
            HttpSession session = req.getSession();
            session.setAttribute("session1", result);
        } catch (NullPointerException npx) {
            //nothing to handle
        }
    }

    //both GET and POST operations are directed to "processRequest" method
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

    //uses the URL to identify the operation
    private String getOperation(StringBuffer requestURL) {

        String op="";
        //identifies the last index of "/" before ".do" and 
        //uses that to put each character after the "/" into "op"
        for(int i= requestURL.lastIndexOf("/",requestURL.indexOf(".do"))+1; i<requestURL.indexOf(".do"); i++)
        {
            op= op+requestURL.charAt(i);
        }
        return op;
    }
}

您可以看到每个操作都是在主 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

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package servlets;

import beans.SeekerCustomer;
import java.io.*;
import java.util.HashMap;
import javax.servlet.*;
import javax.servlet.http.*;
/**
 *
 * @author Dhruv
 */

//servlet class acts as controller by delegating
//operations to the respective Action concrete subclass
public class ControllerServlet extends HttpServlet {

    //stores all the possible operation names
    //and operation objects for quick access
    private HashMap actions;

    @Override
    public void init() throws ServletException {
        actions = new HashMap();

        //all the various operations are stored in the hashmap
        CreateUserAction cua = new CreateUserAction(new SeekerCustomer());
        actions.put(cua.getName(), cua);
        ValidateUserAction vua = new ValidateUserAction(new SeekerCustomer());
        actions.put(vua.getName(), vua);
        ListNonFriendsAction lnfa = new ListNonFriendsAction(new SeekerCustomer());
        actions.put(lnfa.getName(), lnfa);
        AddFriendAction afa = new AddFriendAction(new SeekerCustomer());
        actions.put(afa.getName(), afa);
        ConfirmFriendReqAction cfra = new ConfirmFriendReqAction(new SeekerCustomer());
        actions.put(cfra.getName(),cfra);
        DeclineFriendReqAction dfra = new DeclineFriendReqAction(new SeekerCustomer());
        actions.put(dfra.getName(),dfra);
        AddImageAction aia = new AddImageAction(new SeekerCustomer());
        actions.put(aia.getName(),aia);
        ViewImageAction via = new ViewImageAction(new SeekerCustomer());
        actions.put(via.getName(),via);
        ViewAllImagesAction vaia = new ViewAllImagesAction(new SeekerCustomer());
        actions.put(vaia.getName(),vaia);
        AddTagAction ata = new AddTagAction(new SeekerCustomer());
        actions.put(ata.getName(),ata);
        ViewTagAction vta = new ViewTagAction(new SeekerCustomer());
        actions.put(vta.getName(),vta);
        ViewAllTagsAction vata = new ViewAllTagsAction(new SeekerCustomer());
        actions.put(vata.getName(),vata);
        ViewProfileAction vpa = new ViewProfileAction(new SeekerCustomer());
        actions.put(vpa.getName(),vpa);
        EditAccountAction epa = new EditAccountAction(new SeekerCustomer());
        actions.put(epa.getName(),epa);
        ViewOthersImageAction voia = new ViewOthersImageAction(new SeekerCustomer());
        actions.put(voia.getName(), voia);
        AddOthersTagAction aota = new AddOthersTagAction(new SeekerCustomer());
        actions.put(aota.getName(),aota);
        LogoutAction loa = new LogoutAction(new SeekerCustomer());
        actions.put(loa.getName(), loa);
        ToptagsAction tts = new ToptagsAction(new SeekerCustomer());
        actions.put(tts.getName(), tts);
        UpdateAccountAction uaa = new UpdateAccountAction(new SeekerCustomer());
        actions.put(uaa.getName(), uaa);
        ViewAllFriendsAction vafa = new ViewAllFriendsAction(new SeekerCustomer());
        actions.put(vafa.getName(), vafa);
        ReturnHomeAction rha = new ReturnHomeAction(new SeekerCustomer());
        actions.put(rha.getName(),rha);
    }

    public void processRequest(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {

        //identify the operation from the URL
        String op = getOperation(req.getRequestURL());
        //find and execute corresponding Action
        Action action = (Action)actions.get(op);
        Object result = null;
        try {
            //maintain the session between requests
            result = action.perform(req, resp);
            HttpSession session = req.getSession();
            session.setAttribute("session1", result);
        } catch (NullPointerException npx) {
            //nothing to handle
        }
    }

    //both GET and POST operations are directed to "processRequest" method
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

    //uses the URL to identify the operation
    private String getOperation(StringBuffer requestURL) {

        String op="";
        //identifies the last index of "/" before ".do" and 
        //uses that to put each character after the "/" into "op"
        for(int i= requestURL.lastIndexOf("/",requestURL.indexOf(".do"))+1; i<requestURL.indexOf(".do"); i++)
        {
            op= op+requestURL.charAt(i);
        }
        return op;
    }
}

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.

昨迟人 2024-10-17 16:56:51

生成一个 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.

就是爱搞怪 2024-10-17 16:56:51

我认为这更符合编码标准和最佳实践。

  1. 正确组织您的 Web 应用程序结构,最好使用思维导图来可视化页面和组织,以便您始终可以清楚地了解内容的位置。
  2. 使用一个好的 IDE 工具根据 MVC 的实践来组织内容,其中 View 保存所有 JSP 页面。在内部用它们的组件系列来组织它们,并使用公共文件夹保存公共 JSP 页面。
  3. 使用 Eclipse 的内置搜索功能可以搜索源内容。
  4. 对于长期维护可能有用的方法是使用 Subversion 保留所有源代码,以便您可以比较过去和未来的各个版本的源代码。

I think this is more towards coding standards and best practices here.

  1. Organize your web application structure properly, best to use Mindmap to visualize the pages and the organization so that you can always have clear picture of where stuff were.
  2. Use a good IDE tool to organize stuff according to the practice of MVC where View to keep all your JSP pages. Within organize them with their components family and keep common JSP pages using common folder.
  3. Use built-in Search feature of Eclipse that allow you to search the source contents.
  4. Something might be useful for long run maintenance is to keep all your source code using Subversion so that you could compare various version of source code from past to future.
枉心 2024-10-17 16:56:51
  1. 为类、JSP 等创建一致的命名约定
  2. 根据约定重构您的代码。
  3. 维护它。无一例外
    (如果您需要一些,请考虑重新设计约定)。
  4. 对于转换,尝试拦截呈现阶段并将 JSP 文件名作为注释放入输出中。 (也许这可以帮助直接执行.JSP...
  1. Create consistent naming convention for classes, JSPs, whatever.
  2. Refactor yor code bease to the convention.
  3. Maintain it. No exceptions
    (if you need some, think about redesigning the convention).
  4. For transition try to intercept rendering phase and put JSP file name into ouput as comment. (maybe this can help Exec. JSP directly...)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文