对于struts的标签库运用的不是很熟练,希望各位赐教!
解决方案 »
- 用过jspsmartupload上传文件,进来看看........................
- web.xml中classpath:和classpath*:, 有什么区别?
- 单一用户单点登录
- hibernate疯狂的抛出java.util.ConcurrentModificationException
- 这个高难问题,哪位高手能解决,百分相送!!
- checkstyle检测代码规范中java.header 问题?
- 关于Hibernate的问题
- jive源程序谁有?
- 一个简单的EJB问题
- ORA-07446错
- jbuilder+weblogic的一个session bean客户端lookup时报错
- 请教:在jbuilder7下怎样开发EJB程序,为什么创建ejb的选项总是是灰色的
Action Class:
package test;import org.apache.struts.action.*;
import javax.servlet.http.*;public class TestAction extends Action {
public ActionForward perform(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse res) {
TestForm testForm=(TestForm)form;
String userName=testForm.getUserName();
req.setAttribute("userName",userName);
return mapping.findForward("Test");
}
}
//////////////
Action Form:
package test;import org.apache.struts.action.*;
import javax.servlet.http.*;public class TestForm extends ActionForm { private String userName;
public String getUserName(){
return userName;
}
public void setUserName(String userName){
this.userName=userName;
}
public ActionErrors validate(ActionMapping actionMapping, HttpServletRequest httpServletRequest) {
return null;
}
public void reset(ActionMapping mapping, HttpServletRequest req) {
}
}
/////////////////
Test.jsp
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-template.tld" prefix="template" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ page contentType="text/html; charset=windows-1252" %><html:html>
<head>
<title>
Test
</title>
</head>
<body>
<p>
<html:form action="/testAction.do" method="POST">
<logic:present name="userName">
<bean:write name="userName"/><br>
</logic:present>
userName:<html:text property="userName"/>
<html:submit property="submit" value="Submit"/><html:reset value ="Reset"/>
</html:form>
</body>
</html:html>//////////////
struts-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.0//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd">
<struts-config>
<form-beans>
<form-bean name="testForm" type="test.TestForm" />
</form-beans>
<global-forwards>
<forward name="Test" path="/Test.jsp" />
</global-forwards>
<action-mappings>
<action name="testForm" type="test.TestAction" input="/Test.jsp" scope="request" path="/testAction" />
</action-mappings>
</struts-config>
我现在就是用struts1.0去实现的,实现的过程和仁兄是一样的咯!
唯一不明白的就是:
在jsp文件里用 <logic:present name="userName">
<bean:write name="userName"/>
的意义是什么呢
然后你在进入页面前在正确的SCOPE里初始化好对应的FORMBEAN就可以填充进去了