jsp页面传值到action中
jsp页面:
<c:forEach var="s" items="${news.newsP.list}" varStatus="i" >
<a href="javascript:void(0);" onclick="createNewsHtml('${contextPath}/news/createHtml.do?title=${s.title}&content=${s.content}');return false;" > 生成HTML </a>
</c:forEach>
<script type="text/javascript">
function createNewsHtml(url){
$.ajax( {
global : false,
type : "get",
url :url+"&random="+Math.random(),
async : false,
dataType: 'html',
timeout : 5000,
cache: false,
success : function(resp){
alert("生成成功");
}
});
}
</script>
Action中:
public ActionForward createHtml(){
String title=StrutsEnv.getRequest().getParameter("title");
String content=StrutsEnv.getRequest().getParameter("content");
}
请问下要怎么把title和content的值传到Action当中去,我上面那么做传不到值.
[解决办法]
ajax设置里面type:"GET"大写。提交方式都要大写。有中文的话都转成utf-8
前端都用encodeURI。超链接a标签的onclick的函数里只传url地址不要把参数跟上去。以便于后面好进行encodeURI。onclick改成
onclick="createNewsHtml('${contextPath}/news/createHtml.do');"
ajax设置中url改成
url:url+"?title="+encodeURI('${title}')+"&content="+encodeURI('${content}')+"&random="+Math.random()
[解决办法]
String Name=new String(URLDecoder.decode(request.getParameter("title"),"utf-8"));
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="UTF-8"/>