Ravi Parmar
Ravi Parmar

Reputation: 1452

about jsp source code

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?

Upvotes: 5

Views: 3294

Answers (5)

Rostislav Matl
Rostislav Matl

Reputation: 4543

  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...)

Upvotes: 0

d4v1dv00
d4v1dv00

Reputation: 1021

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.

Upvotes: 0

Eric Giguere
Eric Giguere

Reputation: 3505

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.

Upvotes: 0

Dhruv Gairola
Dhruv Gairola

Reputation: 9182

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.

Upvotes: 3

Harry Joy
Harry Joy

Reputation: 59660

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.

Upvotes: 4

Related Questions