jsp提交到action a.jsp提交到action 以后再返回到a.jsp,要求a.jsp中文本框内容不变,一直显示提交前的内容 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 此回复为自动发出,仅用于显示而已,并无任何其他特殊作用楼主【miaomiao_liming】截止到2008-07-29 12:56:41的历史汇总数据(不包括此帖):发帖的总数量:0 发帖的总分数:0 每贴平均分数:0 回帖的总数量:0 得分贴总数量:0 回帖的得分率:0% 结贴的总数量:0 结贴的总分数:0 无满意结贴数:0 无满意结贴分:0 未结的帖子数:0 未结的总分数:0 结贴的百分比:---------------------结分的百分比:---------------------无满意结贴率:---------------------无满意结分率:---------------------如何结贴请参考这里:http://topic.csdn.net/u/20080501/09/ef7ba1b3-6466-49f6-9d92-36fe6d471dd1.html 把这个值带着,在action里request.setAttribute("aaa",值); 在A.JPS里设默认值.判断默认值是非曲直否为NULL,如果为NULL显示空格,否则显示内容. 然后页面再用getAttribute得到 ..........用struts标签即可<html:form action="对应STRUTS里设定的ACTION和FORM" ><html:text property="Form属性" ... />...</html:form>提交后如果返回来,里面的值还在的.这是1.2里的做法你可以去参考Jpetstore,自己改一下BASEACTION,这样以后写的时候可以直接用FORM来代替ACTION使用. 我看还是贴一下吧,这是参考Jpetstore改的一个BaseActionBaseAction.javapublic class BeanAction extends Action { private Map<String, Method> methods = new HashMap<String, Method>(); @SuppressWarnings("unchecked") private Method getMethod(Class formClass, String methodName) { String key = formClass.getName() + "." + methodName; Method method = methods.get(key); if (method == null) { try { method = formClass.getMethod(methodName, (Class[]) null); methods.put(key, method); } catch (SecurityException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } } return method; } public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { ActionForward forward = mapping.findForward("success"); try { //ActionContext.initialize(request, response); if (form != null) { if(form instanceof BaseBean){ ((BaseBean) form).initForm(mapping, request, response); } // Explicit Method Mapping Method method = null; String methodName = mapping.getParameter(); if (methodName != null && !"*".equals(methodName)) { try { method = getMethod(form.getClass(), methodName); // form.getClass().getMethod(methodName, null); forward = (ActionForward) method.invoke(form, (Object[]) null); } catch (Exception e) { //throw new BeanActionException("Error dispatching bean action via method parameter ('" + methodName + "'). Cause: " + e, e); e.printStackTrace(); } } // Path Based Method Mapping if (method == null && !"*".equals(methodName)) { methodName = mapping.getPath(); if (methodName.length() > 1) { int slash = methodName.lastIndexOf("/") + 1; methodName = methodName.substring(slash); if (methodName.length() > 0) { try { method = getMethod(form.getClass(), methodName);//form.getClass().getMethod(methodName, null);// method = form.getClass().getMethod(methodName, null);// forward = (ActionForward) method.invoke(form, null); forward = (ActionForward) method.invoke(form, (Object[]) null); } catch (Exception e) { //throw new BeanActionException("Error dispatching bean action via URL pattern ('" + methodName + "'). Cause: " + e, e); e.printStackTrace(); } } } } } } catch (Exception e) { //request.setAttribute("BeanActionException", e); throw e; } return forward; }}再来个BaseBean.javapublic abstract class BaseBean extends ActionForm { protected HttpServletRequest request; protected HttpServletResponse response; protected ActionMapping mapping; protected ServletContext servletContext; protected HttpSession session; public void initForm(ActionMapping mapping, HttpServletRequest request, HttpServletResponse response) { this.request = request; this.response = response; this.mapping = mapping; this.session = this.request.getSession(); this.servletContext = this.session.getServletContext(); } public void validate() { } public void reset() { } public void clear() { }} 既然是action,struts组件就可以了..dispatcher JAVA后加'$'符号是指什么? Struts2上传文件的问题 大虾们快来,servlet+mysql程序移植到 freebsd 出错 xml转义符号问题 tomcat5.5 solaris 启动问题 JS问题 关于程序员的视力问题 请教重启应用服务器与classloader的关系? 毫秒级的差异怎么显示? maven web项目本地上好的,部署到服务器上tomcat启动报错 学习J2EE好难 菜鸟问jms用MessageLisener异步接收消息问题
楼主【miaomiao_liming】截止到2008-07-29 12:56:41的历史汇总数据(不包括此帖):
发帖的总数量:0 发帖的总分数:0 每贴平均分数:0
回帖的总数量:0 得分贴总数量:0 回帖的得分率:0%
结贴的总数量:0 结贴的总分数:0
无满意结贴数:0 无满意结贴分:0
未结的帖子数:0 未结的总分数:0
结贴的百分比:---------------------结分的百分比:---------------------
无满意结贴率:---------------------无满意结分率:---------------------
如何结贴请参考这里:http://topic.csdn.net/u/20080501/09/ef7ba1b3-6466-49f6-9d92-36fe6d471dd1.html
然后页面再用getAttribute得到
用struts标签即可
<html:form action="对应STRUTS里设定的ACTION和FORM" >
<html:text property="Form属性" ... />
...
</html:form>提交后如果返回来,里面的值还在的.这是1.2里的做法你可以去参考Jpetstore,自己改一下BASEACTION,这样以后写的时候可以直接用FORM来代替ACTION使用.
BaseAction.javapublic class BeanAction extends Action {
private Map<String, Method> methods = new HashMap<String, Method>();
@SuppressWarnings("unchecked")
private Method getMethod(Class formClass, String methodName) {
String key = formClass.getName() + "." + methodName;
Method method = methods.get(key);
if (method == null) {
try {
method = formClass.getMethod(methodName, (Class[]) null);
methods.put(key, method);
}
catch (SecurityException e) {
e.printStackTrace();
}
catch (NoSuchMethodException e) {
e.printStackTrace();
}
}
return method;
}
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws Exception { ActionForward forward = mapping.findForward("success"); try { //ActionContext.initialize(request, response); if (form != null) { if(form instanceof BaseBean){
((BaseBean) form).initForm(mapping, request, response);
}
// Explicit Method Mapping
Method method = null;
String methodName = mapping.getParameter();
if (methodName != null && !"*".equals(methodName)) {
try {
method = getMethod(form.getClass(), methodName); // form.getClass().getMethod(methodName, null);
forward = (ActionForward) method.invoke(form, (Object[]) null);
} catch (Exception e) {
//throw new BeanActionException("Error dispatching bean action via method parameter ('" + methodName + "'). Cause: " + e, e);
e.printStackTrace();
}
} // Path Based Method Mapping
if (method == null && !"*".equals(methodName)) {
methodName = mapping.getPath();
if (methodName.length() > 1) {
int slash = methodName.lastIndexOf("/") + 1;
methodName = methodName.substring(slash);
if (methodName.length() > 0) {
try {
method = getMethod(form.getClass(), methodName);//form.getClass().getMethod(methodName, null);
// method = form.getClass().getMethod(methodName, null);
// forward = (ActionForward) method.invoke(form, null);
forward = (ActionForward) method.invoke(form, (Object[]) null);
} catch (Exception e) {
//throw new BeanActionException("Error dispatching bean action via URL pattern ('" + methodName + "'). Cause: " + e, e);
e.printStackTrace();
}
}
}
}
} } catch (Exception e) {
//request.setAttribute("BeanActionException", e);
throw e;
} return forward;
}}
再来个BaseBean.javapublic abstract class BaseBean extends ActionForm { protected HttpServletRequest request;
protected HttpServletResponse response;
protected ActionMapping mapping;
protected ServletContext servletContext;
protected HttpSession session;
public void initForm(ActionMapping mapping, HttpServletRequest request,
HttpServletResponse response) {
this.request = request;
this.response = response;
this.mapping = mapping;
this.session = this.request.getSession();
this.servletContext = this.session.getServletContext();
}
public void validate() {
} public void reset() {
} public void clear() {
}}