我的action代码public class writeBlogAction extends ActionSupport {
private static final long serialVersionUID = 1L;
private String titlecc;
private String content; public String getTitlecc() {
return titlecc;
}
public void setTitlecc(String titlecc) {
System.out.println("我被调用了");
this.titlecc = titlecc;
} public String getContent() {
return content;
} public void setContent(String content) {
this.content = content;
} public String writeblog(){
System.out.println(titlecc);
//HttpServletRequest request = ServletActionContext.getRequest();
//String title = request.getParameter("titlecc");
//ActionContext ac=ActionContext.getContext();
//Map<String,Object> map=ac.getParameters();
//String[] strs=(String[])map.get("titlecc");
//System.out.println(strs[0]);
return SUCCESS;
}
}
struts.xml的代码
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="struts2" extends="struts-default" namespace="/">
<action name="newblog" class="lixin.blog.Action.writeBlogAction" method="writeblog" >
<interceptor-ref name="timer"></interceptor-ref>
<result>/publishSuccess.jsp</result>
</action>
</package>
</struts>
web.xml的代码
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts-cleanup</filter-name>
<filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
</filter>
<filter-mapping>
<filter-name>struts-cleanup</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter> <filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
private static final long serialVersionUID = 1L;
private String titlecc;
private String content; public String getTitlecc() {
return titlecc;
}
public void setTitlecc(String titlecc) {
System.out.println("我被调用了");
this.titlecc = titlecc;
} public String getContent() {
return content;
} public void setContent(String content) {
this.content = content;
} public String writeblog(){
System.out.println(titlecc);
//HttpServletRequest request = ServletActionContext.getRequest();
//String title = request.getParameter("titlecc");
//ActionContext ac=ActionContext.getContext();
//Map<String,Object> map=ac.getParameters();
//String[] strs=(String[])map.get("titlecc");
//System.out.println(strs[0]);
return SUCCESS;
}
}
struts.xml的代码
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="struts2" extends="struts-default" namespace="/">
<action name="newblog" class="lixin.blog.Action.writeBlogAction" method="writeblog" >
<interceptor-ref name="timer"></interceptor-ref>
<result>/publishSuccess.jsp</result>
</action>
</package>
</struts>
web.xml的代码
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts-cleanup</filter-name>
<filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
</filter>
<filter-mapping>
<filter-name>struts-cleanup</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter> <filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
<s:form action="newblog" method="post" namespace="/" >
<s:textfield name='titlecc' label="标题" ></s:textfield>
<s:textfield label="内容" name="content"></s:textfield>
<s:submit></s:submit>
</s:form></body>
</html>
运行之后 , titilecc和content最终只能传到parameters中,不能传到valuestack的action中 ,
Struts ValueStack DebugValue Stack Contents
Object Property Name Property Value
lixin.blog.Action.writeBlogAction texts null
content null
actionErrors []
errors {}
fieldErrors {}
errorMessages []
container There is no read method for container
locale zh_CN
actionMessages []
titlecc null
com.opensymphony.xwork2.DefaultTextProvider texts nullStack Context
These items are available using the #key notation
Key Value
com.opensymphony.xwork2.dispatcher.HttpServletRequest org.apache.struts2.dispatcher.StrutsRequestWrapper@cd0f45
application {freeer.Configuration=freeer.template.Configuration@1481ca2, org.apache.catalina.WELCOME_FILES=[Ljava.lang.String;@1fc1ec5, org.apache.catalina.jsp_classpath=/C:/apache-tomcat-6.0.35/webapps/blog2/WEB-INF/classes/;/C:/apache-tomcat-6.0.35/webapps/blog2/WEB-INF/lib/commons-beanutils-1.7.0.jar;/C:/apache-tomcat-6.0.35/webapps/blog2/WEB-INF/lib/commons-fileupload-1.2.2.jar;/C:/apache-tomcat-6.0.35/webapps/blog2/WEB-INF/lib/commons-io-2.0.1.jar;/C:/apache-tomcat-6.0.35/webapps/blog2/WEB-INF/lib/commons-lang-2.5.jar;/C:/apache-tomcat-6.0.35/webapps/blog2/WEB-INF/lib/commons-logging-1.1.1.jar;/C:/apache-tomcat-6.0.35/webapps/blog2/WEB-INF/lib/freeer-2.3.18.jar;/C:/apache-tomcat-6.0.35/webapps/blog2/WEB-INF/lib/javassist-3.11.0.GA.jar;/C:/apache-tomcat-6.0.35/webapps/blog2/WEB-INF/lib/jsf-api.jar;/C:/apache-tomcat-6.0.35/webapps/blog2/WEB-INF/lib/jsf-impl.jar;/C:/apache-tomcat-6.0.35/webapps/blog2/WEB-INF/lib/jstl-1.2.jar;/C:/apache-tomcat-6.0.35/webapps/blog2/WEB-INF/lib/ognl-3.0.4.jar;/C:/apache-tomcat-6.0.35/webapps/blog2/WEB-INF/lib/struts2-core-2.3.1.2.jar;/C:/apache-tomcat-6.0.35/webapps/blog2/WEB-INF/lib/xwork-core-2.3.1.2.jar;/C:/apache-tomcat-6.0.35/lib/;/C:/apache-tomcat-6.0.35/lib/annotations-api.jar;/C:/apache-tomcat-6.0.35/lib/catalina-ant.jar;/C:/apache-tomcat-6.0.35/lib/catalina-ha.jar;/C:/apache-tomcat-6.0.35/lib/catalina-tribes.jar;/C:/apache-tomcat-6.0.35/lib/catalina.jar;/C:/apache-tomcat-6.0.35/lib/ecj-3.7.jar;/C:/apache-tomcat-6.0.35/lib/el-api.jar;/C:/apache-tomcat-6.0.35/lib/jasper-el.jar;/C:/apache-tomcat-6.0.35/lib/jasper.jar;/C:/apache-tomcat-6.0.35/lib/jsp-api.jar;/C:/apache-tomcat-6.0.35/lib/servlet-api.jar;/C:/apache-tomcat-6.0.35/lib/tomcat-coyote.jar;/C:/apache-tomcat-6.0.35/lib/tomcat-dbcp.jar;/C:/apache-tomcat-6.0.35/lib/tomcat-i18n-es.jar;/C:/apache-tomcat-6.0.35/lib/tomcat-i18n-fr.jar;/C:/apache-tomcat-6.0.35/lib/tomcat-i18n-ja.jar;/C:/apache-tomcat-6.0.35/bin/bootstrap.jar;/D:/Program%20Files/Java/jdk1.6.0_22/lib/tools.jar;/D:/Program%20Files/Java/jdk1.6.0_22/jre/lib/ext/dnsns.jar;/D:/Program%20Files/Java/jdk1.6.0_22/jre/lib/ext/localedata.jar;/D:/Program%20Files/Java/jdk1.6.0_22/jre/lib/ext/sunjce_provider.jar;/D:/Program%20Files/Java/jdk1.6.0_22/jre/lib/ext/sunmscapi.jar;/D:/Program%20Files/Java/jdk1.6.0_22/jre/lib/ext/sunpkcs11.jar, org.apache.AnnotationProcessor=org.apache.catalina.util.DefaultAnnotationProcessor@1c7ca6, org.apache.jasper.runtime.JspApplicationContextImpl=org.apache.jasper.runtime.JspApplicationContextImpl@14fd36a, com.sun.faces.config.WebConfiguration=com.sun.faces.config.WebConfiguration@10d4437, .freeer.JspTaglibs=freeer.ext.jsp.TaglibFactory@aba5b9, org.apache.catalina.resources=org.apache.naming.resources.ProxyDirContext@1c0dc00, javax.servlet.context.tempdir=C:\apache-tomcat-6.0.35\work\Catalina\localhost\blog2, .freeer.Application=freeer.ext.servlet.ServletContextHashModel@1f97b85}
com.opensymphony.xwork2.ActionContext.locale zh_CN
com.opensymphony.xwork2.dispatcher.HttpServletResponse org.apache.catalina.connector.ResponseFacade@57487e
com.opensymphony.xwork2.ActionContext.name newblog
current.property.path null
com.opensymphony.xwork2.ActionContext.application {freeer.Configuration=freeer.template.Configuration@1481ca2, org.apache.catalina.WELCOME_FILES=[Ljava.lang.String;@1fc1ec5, org.apache.catalina.jsp_classpath=/C:/apache-tomcat-6.0.35/webapps/blog2/WEB-INF/classes/;/C:/apache-tomcat-6.0.35/webapps/blog2/WEB-INF/lib/commons-beanutils-1.7.0.jar;/C:/apache-tomcat-6.0.35/webapps/blog2/WEB-INF/lib/commons-fileupload-1.2.2.jar;/C:/apache-tomcat-6.0.35/webapps/blog2/WEB-INF/lib/commons-io-2.0.1.jar;/C:/apache-tomcat-6.0.35/webapps/blog2/WEB-INF/lib/commons-lang-2.5.jar;/C:/apache-tomcat-6.0.35/webapps/blog2/WEB-INF/lib/commons-logging-1.1.1.jar;/C:/apache-tomcat-6.0.35/webapps/blog2/WEB-INF/lib/freeer-2.3.18.jar;/C:/apache-tomcat-6.0.35/webapps/blog2/WEB-INF/lib/javassist-3.11.0.GA.jar;/C:/apache-tomcat-6.0.35/webapps/blog2/WEB-INF/lib/jsf-api.jar;/C:/apache-tomcat-6.0.35/webapps/blog2/WEB-INF/lib/jsf-impl.jar;/C:/apache-tomcat-6.0.35/webapps/blog2/WEB-INF/lib/jstl-1.2.jar;/C:/apache-tomcat-6.0.35/webapps/blog2/WEB-INF/lib/ognl-3.0.4.jar;/C:/apache-tomcat-6.0.35/webapps/blog2/WEB-INF/lib/struts2-core-2.3.1.2.jar;/C:/apache-tomcat-6.0.35/webapps/blog2/WEB-INF/lib/xwork-core-2.3.1.2.jar;/C:/apache-tomcat-6.0.35/lib/;/C:/apache-tomcat-6.0.35/lib/annotations-api.jar;/C:/apache-tomcat-6.0.35/lib/catalina-ant.jar;/C:/apache-tomcat-6.0.35/lib/catalina-ha.jar;/C:/apache-tomcat-6.0.35/lib/catalina-tribes.jar;/C:/apache-tomcat-6.0.35/lib/catalina.jar;/C:/apache-tomcat-6.0.35/lib/ecj-3.7.jar;/C:/apache-tomcat-6.0.35/lib/el-api.jar;/C:/apache-tomcat-6.0.35/lib/jasper-el.jar;/C:/apache-tomcat-6.0.35/lib/jasper.jar;/C:/apache-tomcat-6.0.35/lib/jsp-api.jar;/C:/apache-tomcat-6.0.35/lib/servlet-api.jar;/C:/apache-tomcat-6.0.35/lib/tomcat-coyote.jar;/C:/apache-tomcat-6.0.35/lib/tomcat-dbcp.jar;/C:/apache-tomcat-6.0.35/lib/tomcat-i18n-es.jar;/C:/apache-tomcat-6.0.35/lib/tomcat-i18n-fr.jar;/C:/apache-tomcat-6.0.35/lib/tomcat-i18n-ja.jar;/C:/apache-tomcat-6.0.35/bin/bootstrap.jar;/D:/Program%20Files/Java/jdk1.6.0_22/lib/tools.jar;/D:/Program%20Files/Java/jdk1.6.0_22/jre/lib/ext/dnsns.jar;/D:/Program%20Files/Java/jdk1.6.0_22/jre/lib/ext/localedata.jar;/D:/Program%20Files/Java/jdk1.6.0_22/jre/lib/ext/sunjce_provider.jar;/D:/Program%20Files/Java/jdk1.6.0_22/jre/lib/ext/sunmscapi.jar;/D:/Program%20Files/Java/jdk1.6.0_22/jre/lib/ext/sunpkcs11.jar, org.apache.AnnotationProcessor=org.apache.catalina.util.DefaultAnnotationProcessor@1c7ca6, org.apache.jasper.runtime.JspApplicationContextImpl=org.apache.jasper.runtime.JspApplicationContextImpl@14fd36a, com.sun.faces.config.WebConfiguration=com.sun.faces.config.WebConfiguration@10d4437, .freeer.JspTaglibs=freeer.ext.jsp.TaglibFactory@aba5b9, org.apache.catalina.resources=org.apache.naming.resources.ProxyDirContext@1c0dc00, javax.servlet.context.tempdir=C:\apache-tomcat-6.0.35\work\Catalina\localhost\blog2, .freeer.Application=freeer.ext.servlet.ServletContextHashModel@1f97b85}
__component_stack [org.apache.struts2.components.Debug@8f9cc4]
last.property.accessed null
attr org.apache.struts2.util.AttributeMap@1fe1281
com.opensymphony.xwork2.ActionContext.container com.opensymphony.xwork2.inject.ContainerImpl@16df8f5
com.opensymphony.xwork2.dispatcher.ServletContext org.apache.catalina.core.ApplicationContextFacade@22c24e
com.opensymphony.xwork2.ActionContext.session {}
com.opensymphony.xwork2.dispatcher.PageContext org.apache.jasper.runtime.PageContextImpl@43203
com.opensymphony.xwork2.ActionContext.actionInvocation com.opensymphony.xwork2.DefaultActionInvocation@15fdf14
session {}
com.opensymphony.xwork2.util.ValueStack.ValueStack com.opensymphony.xwork2.ognl.OgnlValueStack@12e9ac0
__requestWrapper.getAttribute false
last.bean.accessed null
request {.freeer.Request=freeer.ext.servlet.HttpRequestHashModel@9d7f93, javax.servlet.forward.servlet_path=/newblog.action, struts.valueStack=com.opensymphony.xwork2.ognl.OgnlValueStack@12e9ac0, __cleanup_recursion_counter=1, struts.view_uri=/publishSuccess.jsp, .freeer.TemplateModel={Parameters=freeer.ext.servlet.HttpRequestParametersHashModel@229885, tag=org.apache.struts2.components.Debug@8f9cc4, Request=freeer.ext.servlet.HttpRequestHashModel@9d7f93, .freeer.RequestParameters=freeer.ext.servlet.HttpRequestParametersHashModel@229885, JspTaglibs=freeer.ext.jsp.TaglibFactory@aba5b9, struts=org.apache.struts2.util.StrutsUtil@14b49fc, response=org.apache.catalina.connector.ResponseFacade@57487e, s=org.apache.struts2.views.freeer.tags.StrutsModels@1e659b3, themeProperties={parent=simple}, ognl=org.apache.struts2.views.jsp.ui.OgnlTool@b00f9, session=org.apache.catalina.session.StandardSessionFacade@6d1901, Session=freeer.ext.servlet.HttpSessionHashModel@849e34, Application=freeer.ext.servlet.ServletContextHashModel@1f97b85, request=org.apache.struts2.dispatcher.StrutsRequestWrapper@cd0f45, action=lixin.blog.Action.writeBlogAction@aea1a2, base=/blog2, stack=com.opensymphony.xwork2.ognl.OgnlValueStack@12e9ac0}, struts.request_uri=/blog2/newblog.action, javax.servlet.forward.context_path=/blog2, .freeer.RequestParameters=freeer.ext.servlet.HttpRequestParametersHashModel@229885, javax.servlet.forward.request_uri=/blog2/newblog.action}
action lixin.blog.Action.writeBlogAction@aea1a2
struts.actionMapping org.apache.struts2.dispatcher.mapper.ActionMapping@1e2149c
parameters {content=[Ljava.lang.String;@1b74d4e, titlecc=[Ljava.lang.String;@1345875}
com.opensymphony.xwork2.ActionContext.parameters {content=[Ljava.lang.String;@1b74d4e, titlecc=[Ljava.lang.String;@1345875}忘大神指教 ,这个问题纠结了好几天了,还是没能解决啊