js提交表单,没有进入action中的方法。检查了很久,终究不明白为什么?
在action中有两个方法,findNews和saveNews。findNews能正常执行。当js提交表单访问saveNews的时候,确不进入方法。不知道为什么。。
jsp部分代码:
<script>
function mouerdown(obj){
document.getElementById(obj).style.backgroundImage="url(<%=basePath %>news/images/buttondown.gif)";
document.getElementById(obj).style.borderStyle="solid";
document.getElementById(obj).style.borderColor="#CC0000";
document.getElementById(obj).style.borderWidth="1px";
save();
}
//得到长标题
$("#tit").blur(function(){
var tit=$("#tit").val();
$("#ctit").val(tit);
});
//得到文章内容
function save(){
var tit=$("#tit").val();
var ctit=$("#ctit").val();
var type=""; //文章类型
if($("#ttype").attr("checked")==true){
type="1";
}
if($("#itype").attr("checked")==true){
type="2";
}
if($("#ttype").attr("checked")==true & $("#itype").attr("checked")==true){
type="3";
}
if($("#ttype").attr("checked")==false & $("#itype").attr("checked")==false){
type="0";
}
var pubTime=$("#pubtime").val();
var endTime=$("#endtimer").val();
var tarUrl=$("#targeturl").val();
var wUrl=$("#wurl").val();
var content="";
var g = KE.g["content1"];
if (!g.wyswygMode) {
KE.util.setFullHtml("content1", g.newTextarea.value);
g.iframe.style.display = 'block';
g.newTextarea.style.display = 'none';
//KE.toolbar.able("content1", ['source', 'fullscreen']);
g.wyswygMode = true;
this.isSelected = false;
KE.toolbar.unselect("content1", "source");
content=g.newTextarea.value;
} else {
KE.hideMenu("content1");
g.newTextarea.value = KE.util.getData("content1");
g.iframe.style.display = 'none';
g.newTextarea.style.display = 'block';
//KE.toolbar.disable("content1", ['source', 'fullscreen']);
g.wyswygMode = false;
this.isSelected = true;
KE.toolbar.select("content1", "source");
content=g.newTextarea.value;
}
KE.util.focus("content1");
//内容存放在from表达中
$("#title").val(tit);
$("#ctitle").val(ctit);
$("#type").val(type);
$("#pubDate").val(pubTime);
$("#endDate").val(endTime);
$("#tUrl").val(tarUrl);
$("#wUrl").val(wUrl);
$("#content").val(content);
$("#saveNews").submit();
alert(content); //弹出内容能够成功!
}
</script>
<a target="_bank" onmouseover="mouerover('pub');" onmousedown="mouerdown('pub');" onmouseout="mouerout('pub');" style="cursor:pointer">
<div id="pub" style="width:60px; height:48px;">
<table border="0" width="48" height="20">
<tr>
<td height="10" class="tools" align="center"> <img src="<%=basePath %>news/images/save.gif"></img></td>
</tr>
<tr>
<td align="center" class="tools" ><strong>发布</strong></td>
</tr>
</table>
</div>
</a>
<div style="display: none">
<from action="saveNews.action" name="saveNews" id="saveNews" method="post">
<input type="hidden" name="title" id="title"/><!-- 标题 -->
<input type="hidden" name="ctitle" id="ctitle"/><!-- 长标题 -->
<input type="hidden" name="type" id="type"/> <!-- 文正类型 -->
<input type="hidden" name="pubDate" id="pubDate"/> <!-- 发布时间 -->
<input type="hidden" name="endDate" id="endDate"/> <!-- 下线时间 -->
<input type="hidden" name="tUrl" id="tUrl"/> <!--列表文件地址 -->
<input type="hidden" name="wUrl" id="wUrl"/> <!-- 外部链接 -->
<input type="hidden" name="content" id="content"/> <!--内容 -->
<input type="hidden" name="author" value="${sessionScope.ShUser.shLoginName }"/><!-- 作者 -->
</from>
</div>
struts.xml部分配置:
<!-- 栏目文章列表查询 -->
<action name="*News" class="newsAction" method="{1}News">
<result name="success">/news/articleist.jsp</result>
<result name="pub">/news/pub.jsp</result>
</action>
application.xml部分配置:
<!-- 栏目新闻列表查询 -->
<bean id="newsImpl" class="com.sh.dao.news.NewsImpl">
<property name="gf" ref="session"></property>
</bean>
<bean id="newsServiceImpl" class="com.sh.service.news.NewsServiceImpl">
<property name="news" ref="newsImpl"></property>
</bean>
<bean id="newsAction" class="com.sh.action.news.NewsAction">
<property name="newsService" ref="newsServiceImpl"></property>
</bean>
action代码:
package com.sh.action.news;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.sh.bean.ShNews;
import com.sh.bean.ShType;
import com.sh.bean.ShUser;
import com.sh.service.news.NewsService;
public class NewsAction extends ActionSupport {
private NewsService newsService;//得到services
/*查询文章信息属性*/
private int typeId;//栏目类型ID
private int starPage=1;//初始化为1,默认从第一页开始显示
private int pageSize=16;//初始化16,每页显示16条数据
private int status=3; //文章状态,默认为3,不是草稿、已发布和下线文章
/*保存文章属性*/
private String title;//标题
private String ctitle;//长标题
private int type;//文章类型
private Date pubDate;//发布时间
private Date endDate;//下线时间
private String tUrl;//文章列表所在文件地址
private String wUrl;//外部链接
private StringBuffer content;//文章内容
private String author;//文章作者
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getCtitle() {
return ctitle;
}
public void setCtitle(String ctitle) {
this.ctitle = ctitle;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public Date getPubDate() {
return pubDate;
}
public void setPubDate(Date pubDate) {
this.pubDate = pubDate;
}
public Date getEndDate() {
return endDate;
}
public void setEndDate(Date endDate) {
this.endDate = endDate;
}
public String gettUrl() {
return tUrl;
}
public void settUrl(String tUrl) {
this.tUrl = tUrl;
}
public String getwUrl() {
return wUrl;
}
public void setwUrl(String wUrl) {
this.wUrl = wUrl;
}
public StringBuffer getContent() {
return content;
}
public void setContent(StringBuffer content) {
this.content = content;
}
public int getPageSize() {
return pageSize;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public NewsService getNewsService() {
return newsService;
}
public void setNewsService(NewsService newsService) {
this.newsService = newsService;
}
public int getTypeId() {
return typeId;
}
public void setTypeId(int typeId) {
this.typeId = typeId;
}
public int getStarPage() {
return starPage;
}
public void setStarPage(int starPage) {
this.starPage = starPage;
}
/**
* 根据栏目类型ID得到该栏目下的所有的文章信息
* @author gouwei
* @return String
*/
public String findNews(){
System.out.println("测试saveNews方法 编译,。,,");
// System.out.println("starPage:"+starPage);
ShNews sh=new ShNews();
ShType type=new ShType();
type.setShTypeId(typeId);
sh.setShType(type);
sh.setShNewStatus(status);
System.out.println(sh.getShNewStatus());
List<ShNews> list=newsService.selectNews(sh, starPage, pageSize);//每页16条
int count=newsService.selectNewsCount(sh);
HttpServletRequest request = ServletActionContext.getRequest ();
if(list!=null && count!=0){
request.setAttribute("listNews",list);
request.setAttribute("newCount", count);
request.setAttribute("starpage", starPage);
request.setAttribute("typeId", typeId);
}
return "success";
}
public String saveNews(){
System.out.println("---------------标题:"+title+"-------------------");
System.out.println("------------------------------长标题:"+ctitle+"-------------------------------------");
System.out.println("-----------------------------------作者:"+author+"--------------------发布时间: "+pubDate);
System.out.println("-----------------------------内 容---------------------------------");
System.out.println(content);
System.out.println("-------------------------------------------------------下线时间: "+endDate);
System.out.println("外部链接:"+wUrl);
System.out.println("目标文件:"+tUrl);
return "pub";
}
}
---------------访问findNews代码:------------
<body background="<%=basePath %>news/images/left.gif">
<div class="left">
<script type="text/javascript" src="<%=basePath%>admin/dtree/dtree.js"></script>
<script type="text/javascript">
d = new dTree('d');
d.add('1','-1','后台管理列表','','后台管理列表','main','','','true');
d.add('2','1','新闻管理','','新闻管理','','','','true');
d.add('3','2','211工程简介','findNews.action?typeId=6&userId=402','211工程简介','','','','true');
d.add('4','2','学院动态','findNews.action?typeId=8&userId=402','学院动态','','','','true');
d.add('5','2','图片新闻','findNews.action?typeId=5&userId=402','图片新闻','','','','true');
d.add('6','2','精彩博文','findNews.action?typeId=7&userId=${sessionScope.ShUser.shUserId }','精彩博文','main','','','true');
d.add('7','1','用户管理','','用户管理','','','','true');
d.add('8','7','权限管理','','权限管理','','','','true');
document.write(d);
</script>
</div>
</body>
能访问成功。。。。
把findNews中的代码拷贝在saveNews中。。
在 d.add('6','2','精彩博文','saveNews.action?typeId=7&userId=${sessionScope.ShUser.shUserId }','精彩博文','main','','','true');
能正常访问,。。
肯定不是编译问题,,,编译成功了的。
但是不知道为什么错了。。
估计是在js中出错了。。但是实在是发现不了,那里错了。。
请大家帮我看看。。谢谢le !!