5

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?

jamesmortensen
  • 33,636
  • 11
  • 99
  • 120
Ravi Parmar
  • 1,392
  • 5
  • 24
  • 46
  • Exactly what iw the problem you're trying to solve? If you developed the web application, you have the app's source code. If you are looking for the pages generated by the app, you can view source or use a proxy server (the equivalant of viewing the source). If you can provide an exMple of the problem you're trying to solve, it'll be easier to give a good answer. – atk Jan 03 '11 at 06:24
  • This question reminds me of a problem I often have. I use lots of `.jspf` fragments, and when I watch the completely generated page in a browser it is hard to know in which file a particular HTML element has been defined. Some hints are the `id` and `class` attributes, but that's all I usually have. One could add a common header to all those `.jspf` files that prints their name as an HTML comment (but only if a special URL parameter is given, for example). I don't think this is usually done though. – Roland Illig Jan 03 '11 at 06:41
  • First of alll thanks .. I have developed a web application that have thousands of .jsp pages.. and also i can find any of .jsp pages with help of actions but it take some time .. My question is there any any way or tools through with i can find any jsp page directly .. For Ex...... If there is list.jsp page in admin side and i want to go on this page soruce code direclty without referring any action .. so i can change this list.jsp page easily.... – Ravi Parmar Jan 03 '11 at 08:06
  • Why can't you use a search across all the .jsp files to find which files might contain the fragment of interest? – Ira Baxter Feb 03 '11 at 07:23

5 Answers5

4

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.

Harry Joy
  • 58,650
  • 30
  • 162
  • 207
  • yes .. i have used MyEclispe .. I didnt get wt u mean to say ..? – Ravi Parmar Jan 03 '11 at 08:05
  • @water: use ctrl+shift+r to find your desire JSP page. – Harry Joy Jan 03 '11 at 08:35
  • oh.... dear.. i knw already that .. i want to find it from UI part ... GOt it .. ???But anyway .. thanks a lot. i can solved .. – Ravi Parmar Jan 03 '11 at 08:49
  • 1
    @water: if you are using MyEclipse then you can also get a UI view and access same object in code directly. Like if you fcous on table row in UI view then you can directly switch to the code for the row in code view. Hope you get my point. – Harry Joy Feb 01 '11 at 04:15
3

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.

Dhruv Gairola
  • 9,102
  • 5
  • 39
  • 43
  • no probs! and i really hope you're not merely using JSP pages for your web application, rather, using JSP with servlets and java beans (at the least) as part of the MVC pattern. merely using JSP only might be part of the reason you're having problems (and is a bad practice). – Dhruv Gairola Jan 03 '11 at 08:30
  • no no .. I have strictly follow MVC pattern Dear.... but there are lots of jsp pages and all are dynamic jsp pages .. .... – Ravi Parmar Jan 03 '11 at 08:34
  • ok thats good! i guess patterns and proper naming will help.. but yeah, having many jsp pages is understandable and slightly hard to manage.. try templates to abstract out common functionality.. – Dhruv Gairola Jan 03 '11 at 08:44
0

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.

Eric Giguere
  • 3,495
  • 15
  • 11
0

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.
d4v1dv00
  • 971
  • 4
  • 10
  • 21
0
  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...)
Community
  • 1
  • 1
Rostislav Matl
  • 4,294
  • 4
  • 29
  • 53