67,513
社区成员
发帖
与我相关
我的任务
分享
<!--新增加的模块!功能是登陆进去根据登录用户的session取出用户的相应信息 -->
<action path="/newtask" scope="request" validate="false"
type="com.coreram.framework.common.action.NewTask" parameter="method" >
<forward name="ok" path="/success.jsp"/>
</action>
package com.coreram.framework.common.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.springframework.web.struts.DispatchActionSupport;
public class NewTask extends DispatchActionSupport{
public ActionForward newtask(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
if ("tom".equals("tom")) {
return mapping.findForward("ok");
}
return null;
}
}
function doNewsTask(){
//task.jsp一开始加载首先调用这个函数,把action传过去,获取到当前session的username!!!
try {
//alert("error");
//location.href ="/Test.jsp";这种写法是正确的!!
//window.location.href="/Test.jsp"; 这种写法是错误的!!
var url="/newtask.do";
window.location.href=url;
}
catch(e)
{alert("wrong");}
}
<global-exceptions>
<exception key="general.exception" type="java.lang.Exception"
scope="request" handler="com.coreram.framework.exception.RedirectExceptionHandler"
path="/error.jsp" />
</global-exceptions>
public class RedirectExceptionHandler
extends ExceptionHandler {
private static org.apache.log4j.Logger logger = org.apache.log4j.LogManager.getLogger("RedirectExceptionHandler");
public ActionForward execute(Exception ex,
ExceptionConfig ae,
ActionMapping mapping,
ActionForm formInstance,
HttpServletRequest request,
HttpServletResponse response) throws
ServletException {
ActionForward forward = null;
ActionError error = null;
String property = null;
if (ae.getPath() != null) {
forward = new ActionForward(ae.getPath(),true);
}
else {
forward = mapping.getInputForward();
}
// Figure out the error
if (ex instanceof ModuleException) {
error = ( (ModuleException) ex).getError();
property = ( (ModuleException) ex).getProperty();
}
else {
logger.error(ex.getMessage());
error = new ActionError(ae.getKey(), ex.getMessage());
property = error.getKey();
}
// Store the exception
request.setAttribute(com.coreram.framework.Globals.KEY_ERROR_MESSAGE, ex.getMessage());
storeException(request, property, error, forward, ae.getScope());
return forward;
}
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'Test.jsp' starting page</title>
</head>
<body>
<form action="TestAction.do" method="get">
<input type="text" maxlength="12" name="userno">
<input type="submit" value="OK!">
</form>
</body>
</html>
package com.coreram.framework.common.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import com.coreram.framework.manager.sysuser.SysUser;
import com.coreram.framework.util.Pub;
public class TestAction extends DispatchAction {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
try {
String userno = Pub.val(request, "userno");
if (userno.equals("tom")) {
return mapping.findForward("success");
}
//SysUser user = (SysUser)request.getSession().getAttribute("cur_user");
//System.out.println(user.getUsername());
//System.out.println(user.getUserno());
//SysUser user = (SysUser) request.getSession().getAttribute(com.coreram.framework.Globals.USER_KEY);
} catch (Exception e) {
}
return mapping.findForward("failed");
}
}
求高人指点啊!!