一个javaBean的问题

fly304821548 2010-03-24 11:28:32
我想写个留言页面,出现以下错误:

2010-3-24 11:21:43 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 31 in the jsp file: /addMessage.jsp
Generated servlet error:
msg cannot be resolved


at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:414)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:297)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:303)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:88)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
...全文
118 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
24K純帥 2010-03-25
  • 打赏
  • 举报
回复
不是说错误是这个嘛31 in the jsp file: /addMessage.jsp
py330316117 2010-03-25
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 wts 的回复:]

An error occurred at line: 31 in the jsp file: /addMessage.jsp
Generated servlet error:
msg cannot be resolved
这句不是已经说的很清楚了么?msg变量找不到,在addMessage.jsp这个文件里。
就是
try {
messageBean.setMsg(msg);
me……
[/Quote]
不是太明白,顶下吧,根据英语翻译,异常好像是这个地方
fly304821548 2010-03-24
  • 打赏
  • 举报
回复
以下是jsp页面出错信息:

HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 31 in the jsp file: /addMessage.jsp
Generated servlet error:
msg cannot be resolved


org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:88)


root cause

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 31 in the jsp file: /addMessage.jsp
Generated servlet error:
msg cannot be resolved


org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:414)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:297)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:303)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:88)


note The full stack trace of the root cause is available in the Apache Tomcat/5.5.17 logs.
Ark032425 2010-03-24
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 hedangqing 的回复:]
看addMessage.jsp 就好了

应该是你boby 里面java 写错了
你先把body 里面java 代码全删了,再多调试几下
[/Quote]
报错第几行,可以看jsp翻译后的java文件。行数与之对应
2到20个英文 2010-03-24
  • 打赏
  • 举报
回复
看addMessage.jsp 就好了

应该是你boby 里面java 写错了
你先把body 里面java 代码全删了,再多调试几下

fly304821548 2010-03-24
  • 打赏
  • 举报
回复
以下是viewMessage.jsp页面,总的就这3个页面

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ page import="java.sql.*,com.efound.data.javaBean.*,java.util.*" %>
<jsp:useBean id="messgaeBean" class="com.efound.data.javaBean.MessageBean" scope="page"/>
<html>
<head>
<base href="<%=basePath%>">

<title>显示留言消息</title>

<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">
-->

</head>

<body>
<p align="center">所有访客留言</p>
<hr>
<%
int message_count=0;
Collection messages=messageBean.getMessage();
Iterator it=messages.iterator();
while(it.hasNext()) {
MessageVO message=(MessageVO)it.next();
%>
<TABLE width="100%" align="center" border=1 brcolor=99ccff cellspacing="0" cellpadding="0"
bordercolordark="#000000" bordercolorlight="#CCCC99">

<tr><td bgcolor="#CCCC99"><font size=2>主题:</font></td>
<td colspan=3><%=message.getTitle() %></td></tr>
<tr><td bgcolor="#CCCC99"><font size=2>留言人:</font></td>
<td><%=message.getName() %></td>
<td bgcolor="#CCCC99"><font size=2>E-mail:</font></td>
<td>
<%
out.println("<a href=mailto:"+message.getEmail()+">"+message.getEmail()+"</a>");
%>
</td>
</tr>

<tr><td bgcolor="#CCCC99"><font size=2>留言时间:</font></td><td colspan=3>
<%
out.println("<font size=2>"+message.getDate().toLocaleString()+"</font>");
%>
</td></tr>

<tr><td align="center">
<%
out.println("("+message_count+")");
%>
</td>

<td colspan=3><%=message.getContent() %>
</td></tr>
</TABLE>
<%
out.println("<hr>");
message_count++;
}
%>
<p align="center"><a href="index.html">我要留言</a></p>
</body>
</html>
fly304821548 2010-03-24
  • 打赏
  • 举报
回复
以下是register.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'register.jsp' starting page</title>

<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">
-->

</head>

<body>
<TD>
<TABLE align="center" border=1 cellspacing="0" cellpadding="0"
bordercolordark="#CCCC99" bordercolorlight="#CCCC99">

<FORM ACTION="addMessage.jsp">


<TR>
<TD>
姓名:
</TD>
<TD bgcolor="#CCCC99">
<input type="text" name="name" size=25>
</TD>
</TR>

<TR>
<TD bgcolor="#CCCC99">
E-mail:
</TD>
<TD bgcolor="#CCCC99">
<input type="text" name="email" size=25>
</TD>
</TR>

<TR>
<TD>
主题:
</TD>
<TD bgcolor="#CCCC99">
<input type="text" name="title" size=25>
</TD>
</TR>

<TR>
<TD align="top" bgcolor="#CCCC99">
留言:
</TD>
<TD>
<textarea name="content" rows=7 cols=25></textarea>
</TD>
</TR>

<TR>
<TD colspan=3>
<TABLE align="center" width="100%" cellspacing="0" cellpadding="0"
bordercolordark="#CCCC99" bordercolorlight="#CCCC99">
<TR>
<TD align="center" bgcolor="#CCCC99">
<input type="submit" value="提交留言">
</TD>
<TD align="center">
<a href="viewMessages.jsp"><font size=2>查看留言 </font></a>
</TD>
<TD align="center" bgcolor="#CCCC99">
<input type="reset" value="重新填写">
</TD>
</TR>
</TABLE>
</TD>
</TR>

</FORM>
</TABLE>
</TD>
</body>
</html>
fly304821548 2010-03-24
  • 打赏
  • 举报
回复
以下是addMessage.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ page import="java.sql.*,com.efound.data.javaBean.*,java.util.*" errorPage="../error.jsp" %>
<jsp:useBean id="messageVO" class="com.efound.data.javaBean.MessageVO" scope="page">
<jsp:setProperty name="messageVO" property="*"/>
</jsp:useBean>
<jsp:useBean id="messageBean" class="com.efound.data.javaBean.MessageBean" scope="page"/>
<html>
<head>
<base href="<%=basePath%>">

<title>添加信息表</title>

<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">
-->

</head>

<body>
<%
try {
messageBean.setMsg(msg);
messageBean.addMessage();
}
catch(Exception e) {
e.printStackTrace();
}
%>
<jsp:forward page="viewMessages.jsp"/>
</body>
</html>
2到20个英文 2010-03-24
  • 打赏
  • 举报
回复
Unable to compile class for JSP

页面写错了
把你jsp页面贴出来看下

fly304821548 2010-03-24
  • 打赏
  • 举报
回复
只写了2个类,一个是messageVO 类,javaBean的,比较简单,不列出来,一个是链接数据库的:


public class MessageBean {
private Connection con;

MessageVO msg;

public MessageBean() {
String CLASSFORNAME = "com.mysql.jdbc.Driver";
String URL = "jdbc:mysql//localhost:8888/test/";
String username = "root";
String password = "123456";

try {
Class.forName(CLASSFORNAME);
con = DriverManager.getConnection(URL,username,password);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}

public void setMsg(MessageVO msg) {
this.msg = msg;
}

public void addMessage() throws Exception {
try {
PreparedStatement stm = con.prepareStatement("insert into messagevo values(?,?,?,?,?,?)");
stm.setInt(1, msg.getId());
stm.setString(2, msg.getTitle());
stm.setString(3, msg.getName());
if ((msg.getEmail()).length() == 0)
stm.setString(4, null);
else
stm.setString(4, msg.getEmail());
stm.setString(5, msg.getContent());
stm.setDate(6, new java.sql.Date(new java.util.Date().getTime()));

try {
stm.executeQuery();
} catch (SQLException e) {
e.printStackTrace();
}

con.close();
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}

public Collection getMessage() throws Exception {
Collection<MessageVO> ret = new ArrayList<MessageVO>();
try {
Statement stm = con.createStatement();
ResultSet result = stm.executeQuery("select count(*) from message");
int message_count = 0;
if(result.next()) {
message_count = result.getInt(1);
result.close();
}

if(message_count > 0) {
result = stm.executeQuery("select * from message order by Date desc");
while (result.next()) {
String title = result.getString("Title");
String name = result.getString("Name");
String email = result.getString("Email");
String content = result.getString("Content");
java.sql.Date date = result.getDate("Date");
MessageVO message = new MessageVO();
message.setName(name);
message.setTitle(title);
message.setContent(content);
message.setDate(date);
message.setEmail(email);
ret.add(message);
}
result.close();
stm.close();
}
con.close();
}
catch(Exception e) {
e.printStackTrace();
throw e;
}
return ret;
}
}
wts 2010-03-24
  • 打赏
  • 举报
回复
An error occurred at line: 31 in the jsp file: /addMessage.jsp
Generated servlet error:
msg cannot be resolved
这句不是已经说的很清楚了么?msg变量找不到,在addMessage.jsp这个文件里。
就是
try {
messageBean.setMsg(msg);
messageBean.addMessage();
}
这段代码出错了。
你这里用了msg,但那里也没声明msg这个变量
w2512149 2010-03-24
  • 打赏
  • 举报
回复
/addMessage.jsp.................................................
2到20个英文 2010-03-24
  • 打赏
  • 举报
回复
把你addMessage.jsp中java 全部删除

最愚蠢的办法
排除法

62,621

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧