Java 关于jsp源代码
我开发了一个非常大的Web应用程序。如果我需要在JSP页面中进行任何更改,那么查找该JSP页面、链接、操作等将花费太多时间 那么,是否有任何工具或技术可以让我直接获得特定JSP页面的代码Java 关于jsp源代码,java,jsp,Java,Jsp,我开发了一个非常大的Web应用程序。如果我需要在JSP页面中进行任何更改,那么查找该JSP页面、链接、操作等将花费太多时间 那么,是否有任何工具或技术可以让我直接获得特定JSP页面的代码 我认为“观点来源”是不同的。它只显示该JSP的源?您是否尝试过NetBeans或Eclipse或MyEclipse或任何其他IDE? 您可以使用此工具的快捷方式在应用程序中查找适当的代码。 它们可以帮助您更快地在应用程序中找到JSP页面。技术——您可以使用适当的设计模式对代码进行分段,使每个JSP页面都表示“操
我认为“观点来源”是不同的。它只显示该JSP的源?您是否尝试过NetBeans或Eclipse或MyEclipse或任何其他IDE? 您可以使用此工具的快捷方式在应用程序中查找适当的代码。 它们可以帮助您更快地在应用程序中找到JSP页面。技术——您可以使用适当的设计模式对代码进行分段,使每个JSP页面都表示“操作”,例如addFriendAction.JSP。这里的优点是,查找适当的页面名称会更容易,因为您只需引用相应的操作。将此与在同一页面中包含多个操作的JSP页面进行比较。下面是一个例子(我假设您正在按照MVC模式使用servlet和jsp页面)。e、 g.使用命令模式将web应用程序结构化为操作(参考代码示例4.8-) 除此之外,让我分享一下我最近做的一个利用这种模式的项目。下面是我的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;
进口豆子。SeekerCustomer;
导入java.io.*;
导入java.util.HashMap;
导入javax.servlet.*;
导入javax.servlet.http.*;
/**
*
*@作者Dhruv
*/
//servlet类通过委托充当控制器
//对相应Action-concrete子类的操作
公共类ControllerServlet扩展了HttpServlet{
//存储所有可能的操作名称
//和操作对象,以便快速访问
私有HashMap操作;
@凌驾
public void init()引发ServletException{
actions=newhashmap();
//所有的各种操作都存储在hashmap中
CreateUserAction cua=新建CreateUserAction(新建SeekerCustomer());
actions.put(cua.getName(),cua);
ValidateUserAction vua=新的ValidateUserAction(新SeekerCustomer());
actions.put(vua.getName(),vua);
ListNonFriendAction lnfa=新建ListNonFriendAction(新建SeekerCustomer());
actions.put(lnfa.getName(),lnfa);
AddFriendAction afa=新的AddFriendAction(新SeekerCustomer());
actions.put(afa.getName(),afa);
ConfirmFriendReqAction cfra=新ConfirmFriendReqAction(新SeekerCustomer());
actions.put(cfra.getName(),cfra);
DeclineFriendReqAction dfra=新DeclineFriendReqAction(新SeekerCustomer());
actions.put(dfra.getName(),dfra);
AddImageAction aia=新的AddImageAction(新SeekerCustomer());
actions.put(aia.getName(),aia);
ViewImageAction via=newviewImageAction(new SeekerCustomer());
actions.put(via.getName(),via);
VIEWALIMAGESACTION vaia=新VIEWALIMAGESACTION(新SeekerCustomer());
actions.put(vaia.getName(),vaia);
AddTagAction ata=新的AddTagAction(新SeekerCustomer());
actions.put(ata.getName(),ata);
ViewTagAction vta=新的ViewTagAction(新的SeekerCustomer());
actions.put(vta.getName(),vta);
ViewAllTagsAction vata=新建ViewAllTagsAction(新建SeekerCustomer());
actions.put(vata.getName(),vata);
ViewProfileAction vpa=新的ViewProfileAction(新的SeekerCustomer());
actions.put(vpa.getName(),vpa);
EditAccountAction epa=新的EditAccountAction(新的SeekerCustomer());
actions.put(epa.getName(),epa);
ViewOthersImageAction voia=新建ViewOthersImageAction(新建SeekerCustomer());
actions.put(voia.getName(),voia);
AddOthersTagAction aota=new AddOthersTagAction(new SeekerCustomer());
actions.put(aota.getName(),aota);
LogoutAction loa=新的LogoutAction(new SeekerCustomer());
actions.put(loa.getName(),loa);
ToptagsAction tts=新ToptagsAction(新SeekerCustomer());
actions.put(tts.getName(),tts);
UpdateAccountAction uaa=新的UpdateAccountAction(new SeekerCustomer());
actions.put(uaa.getName(),uaa);
ViewAllFriendsAction vafa=新建ViewAllFriendsAction(新建SeekerCustomer());
actions.put(vafa.getName(),vafa);
ReturnHomeAction rha=新的ReturnHomeAction(新SeekerCustomer());
actions.put(rha.getName(),rha);
}
public void processRequest(HttpServletRequest-req,HttpServletResponse-resp)引发IOException,ServletException{
//从URL中标识操作
字符串op=getOperation(req.getRequestURL());
//查找并执行相应的操作
Action Action=(Action)actions.get(op);
对象结果=空;
试一试{
//在请求之间维护会话
结果=动作。执行(请求、响应);
HttpSession session=req.getSession();
session.setAttribute(“session1”,结果);
}捕获(NullPointerException npx){
//没什么可处理的
}
}
//GET和POST操作都指向“processRequest”方法
@凌驾
受保护的void doGet(HttpServletRequest请求、HttpServletResponse响应)
抛出ServletException、IOException{
processRequest(请求、响应);
}
@凌驾
受保护的void doPost(HttpServletRequest请求、HttpServletResponse响应)
抛出ServletException、IOException{
processRequest(请求、响应);
}
//使用URL标识操作
私有字符串getOperation(StringBuffer请求URL){
字符串op=“”;
//标识“/”before.do”和的最后一个索引
//使用它将“/”后面的每个字符放入“o”