贡献100分,请教一个问题

yanxibang 2005-10-12 03:53:38
如何扩充action类,从哪些方面?
如能给出好的代码,另开贴给100分
...全文
108 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
TinyJimmy 2005-10-13
  • 打赏
  • 举报
回复
晕,这200分没人想要吗
==========================

最好还是把你200分收回, 自己好好找找资料.
Maple99 2005-10-13
  • 打赏
  • 举报
回复
建议你看看孙卫勤的 精通struct,里面有详细的介绍
yanxibang 2005-10-13
  • 打赏
  • 举报
回复
晕,这200分没人想要吗
yanxibang 2005-10-13
  • 打赏
  • 举报
回复
就是要写一个action基类,完成错误处理,跳转控制,减少具体action类中的代码
mxlmwl 2005-10-13
  • 打赏
  • 举报
回复
完成错误处理,跳转控制,减少具体action类中的代码

=======================
这是什么意思?什么错误处理?ActionError么?formbean本身不是已经进行了一层拦截了么
跳转控制用mapping.findForward,就这么一句话,你还想怎么做?

减少具体action类中的代码,这个问题问的太没水准了吧,这要看你的实际情况了啊。
一般是把业务逻辑写到Service中,action中只是简单调用业务层的方法而已,已经简化了,你还想如何简化呢?

把你的实际需求说出来让大家帮你参谋一下,你现在的这个想法首先就未必是对的。
mxlmwl 2005-10-12
  • 打赏
  • 举报
回复
应该是扩展RequestProcessor吧?action中就一个execute方法,没什么好扩充的。而且structs1.2之后的版本都是通过RequestProcessor来实行总调度的。
  • 打赏
  • 举报
回复
原来是要扩展Action ,不好意思。呵呵
  • 打赏
  • 举报
回复
见,小孙的精通struts.
  • 打赏
  • 举报
回复
package netstore.framework;

import javax.servlet.http.*;
import javax.servlet.RequestDispatcher;
import java.util.Locale;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.RequestProcessor;
import org.apache.struts.config.ForwardConfig;
import org.apache.struts.Globals;

/**
* A customized RequestProcessor that checks the user's preferred Locale
* from the request each time. If a Locale is not in the session or
* the one in the session doesn't match the request, the Locale in the
* request is set to the session.
*/
public class CustomRequestProcessor extends RequestProcessor {

protected void processLocale(HttpServletRequest request,
HttpServletResponse response) {

// Are we configured to select the Locale automatically?
if (!moduleConfig.getControllerConfig().getLocale()) {
return;
}

// Get the Locale (if any) that is stored in the user's session
HttpSession session = request.getSession();
Locale sessionLocale = (Locale)session.getAttribute(Globals.LOCALE_KEY);

// Get the user's preferred Locale from the request
Locale requestLocale = request.getLocale();

// If was never a Locale in the session or it has changed, set it
if (sessionLocale == null || (sessionLocale != requestLocale) ){
if (log.isDebugEnabled()) {
log.debug(" Setting user locale '" + requestLocale + "'");
}
// Set the new Locale into the user's session
session.setAttribute( Globals.LOCALE_KEY, requestLocale );
}
}

protected boolean processPreprocess( HttpServletRequest request,
HttpServletResponse response){

boolean continueProcessing = true;

// Get the name of the remote host and log it
String remoteHost = request.getRemoteHost();
log.info( "Request from host: " + remoteHost );

// Make sure the host is from one that you expect
if ( remoteHost == null || !remoteHost.startsWith( "127.") ){
// Not the localhost, so don't allow the host to access the site
continueProcessing = false;

ForwardConfig config = moduleConfig.findForwardConfig("Unauthorized");
try{
response.sendRedirect( config.getPath() );
}catch( Exception ex ){
log.error( "Problem sending redirect from processPreprocess()" );
}
}

return continueProcessing;
}
}


struts-config.xml
<controller
contentType="text/html;charset=GB2312"
locale="true"
nocache="true"
processorClass="org.apache.struts.action.RequestProcessor"/>


asa516 2005-10-12
  • 打赏
  • 举报
回复
不懂,帮你up
majy 2005-10-12
  • 打赏
  • 举报
回复
action就一个转发类,没啥搞头吧,业务逻辑写这里也不是很合适
onray 2005-10-12
  • 打赏
  • 举报
回复
楼主指的扩充 是什么意思
我一般会用DynamicAction 来做

67,538

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧