50分请高手指教!我用struts+hibernate做一个系统,为什么会出现如下问题
显示的页面,在html中能显示表单,但是在tomcat下运行jsp,却无法显示表,之显示最上面的按钮.
我下午在学校机房测试,当时是能显示的,但是晚上在我自己的电脑上就不能了.页面代码如下.
<%@ page language="java" pageEncoding="GB18030"%>
<%@taglib uri="/WEB-INF/struts-html.tld"prefix="html" %>
<%@taglib uri="/WEB-INF/struts-logic.tld"prefix="logic" %>
<%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<html>
<head>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<metahttp-equiv="Content-Type"content="text/html;charset=ISO-8859-1">
<title></title>
</head>
<body>
<h1 align="center">欢迎你! <%=request.getSession().getAttribute("username") %> </h1>
<html:form method="post" action="/checkaddmessage.do">
<html:submit value="发布新消息"></html:submit>
</html:form>
<br>
<br>
<br>
现有的消息
<br>
<TABLE id="id1" style="BORDER-RIGHT:darkgreen lpx solid;BORDER-TOP:
darkgreen lpx solid;BORDER-LEFT:darkgreen lpx solid;WIDTH:100%;
BORDER-BOTTM:darkgreen lpx solid;BORDER-COLLAPSE:collapse"
borderCorlor="darkgreen"cellspacing="0"border="1">
<logic:notEmpty name="messageList" >
<tr>
<TD noWrap><b> 消息</b></TD><br>
<TD noWrap><b> 内容</b></TD><br>
<TD noWrap><b> 作者</b></TD><br>
<TD ><b> 动作</b></TD><br>
<TD ><b> 时间</b></TD><br>
</tr>
<logic:iterate indexId="index" id="item" name="messageList" >
<tr>
<td class="allcapsCcenter">
<bean:write name="item" property="id"/>
</td>
<td class="allcapsCenter">
<bean:write name="item" property="content"/></td>
<td><bean:write name="item" property="author"/></td>
<td nowrap class="center">
<html:form method="post" action="/checkeditmessage.do">
<html:submit value="修改"></html:submit>
<inpute type="hidden" id="id"name="id"/>
<inpute type="hidden" id="author"name="author"/>
</html:form>
</td>
<td class="allcapsCenter">
<bean:write name="item" property="date"/></td>
</tr>
</logic:iterate>
</logic:notEmpty>
</TABLE>
<html:form action="/checkeditmessage.do" method="post">
<inpute type="hidden" id="hid"name="hid"/>
</html:form>
</body>
<script language="Javascript">
<!--
function submitSid(form,.hid){
form.hid.value=hid;
form.submit();
}
//-->
</script>
</html>
上面是jsp页面显示的代码,下面是struts的action,action没有问题,问题出在jsp页面上
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.yourcompany.struts.action;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import com.message.Message;
import com.yourcompany.struts.form.MessageForm;
/**
* MyEclipse Struts
* Creation date: 10-21-2008
*
* XDoclet definition:
* @struts.action path="/showNews" name="messageForm" scope="request" validate="true"
* @struts.action-forward name="success" path="/form/showMessage.jsp"
* @struts.action-forward name="false" path="/form/login.jsp"
*/
public class ShowNewsAction extends Action {
/*
* Generated Methods
*/
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
MessageForm messageForm = (MessageForm) form;// TODO Auto-generated method stub
if(request.getSession().getAttribute("username")==null)
{
return mapping.findForward("false");
}
else
{try
{
ArrayList messageList =new ArrayList();
SessionFactory sf=new Configuration().configure().buildSessionFactory();
Session session=sf.openSession();
Transaction tx=session.beginTransaction();
Message message=new Message();
//String sqlQuery="from message";
String sqlQuery="select u from Message u ";
Query lQuery=session.createQuery(sqlQuery);
messageList=(ArrayList)lQuery.list();
tx.commit();
session.close();
//messageForm.setMessageList(messageList);
request.getSession().setAttribute("messageList", messageList);
return mapping.findForward("success");
}catch (Exception e)
{
System.out.println("出错了:"+ e);
return mapping.findForward("false");
}
}
}
}
[解决办法]
楼主,请将错误日志贴出来吧!
这样有利于解决问题!