各位大侠 帮我看看这代码啊  可以帮我具体分析一下下面的代码吗 ? 万分感激哦 在线等啊~~ 
 1 .
package framework;import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.ResourceBundle;import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;public class ActionServlet extends HttpServlet
{ protected HashMap events = new HashMap();
  protected HashMap pages = new HashMap();
 
  public void init() throws ServletException
  {
    ResourceBundle bundle = ResourceBundle.getBundle("properties/events");
    Enumeration e = bundle.getKeys();
    try
    {
while(e.hasMoreElements())
{
           String key = (String)e.nextElement();
       String value = bundle.getString(key);
         EventHandler event =(EventHandler)Class.forName(value).newInstance();
         events.put(key,event);
}

bundle = ResourceBundle.getBundle("properties/pages");
Enumeration enu = bundle.getKeys();
while(enu.hasMoreElements())
{
String key = (String)enu.nextElement();
String value = bundle.getString(key);
pages.put(key,value);
}
}
catch(Exception ex)
{
ex.printStackTrace();
}    
  }
    
    
public void doGet(HttpServletRequest req,HttpServletResponse rep)
throws ServletException,IOException
{
doPost(req,rep);
}
     
     
public void doPost(HttpServletRequest req,HttpServletResponse rep)
throws ServletException,IOException
{
try
{
req.setCharacterEncoding("gb2312");
String event = this.getActionKey(req);

RequestDispatcher dis = null;
if(event==null||(!events.containsKey(event)))
{
event = "index";
dis = req.getRequestDispatcher((String)pages.get(event)); 
dis.forward(req,rep);
}
else
{
EventHandler handle = (EventHandler)events.get(event);
handle.process(req,rep);
dis = req.getRequestDispatcher((String)pages.get(handle.getURL())); 
dis.forward(req,rep);
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
}

private String getActionKey(HttpServletRequest req){
String path = req.getServletPath();
System.out.println(path);
int slash = path.lastIndexOf("/");
int period = path.lastIndexOf(".");
if(period > 0 && period > slash){
path = path.substring(slash+1,period);
}
System.out.println(path);
return path;
}}
2 .
package framework;import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;public abstract class EventHandler 
{
private String url;

public void setURL(String url)
{
this.url=url;
}

public  String getURL()
{
return this.url;
}

public abstract void process(HttpServletRequest req,HttpServletResponse rep)
throws ServletException,IOException;
}

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【zpball】截止到2008-07-09 00:31:53的历史汇总数据(不包括此帖):
    发帖的总数量:0                        发帖的总分数:0                        每贴平均分数:0                        
    回帖的总数量:2                        得分贴总数量:0                        回帖的得分率:0%                       
    结贴的总数量:0                        结贴的总分数:0                        
    无满意结贴数:0                        无满意结贴分:0                        
    未结的帖子数:0                        未结的总分数:0                        
    结贴的百分比:---------------------结分的百分比:---------------------
    无满意结贴率:---------------------无满意结分率:---------------------
    如何结贴请参考这里:http://topic.csdn.net/u/20080501/09/ef7ba1b3-6466-49f6-9d92-36fe6d471dd1.html