若能解决肯定结贴 servlet 留言板 The requested resource is not available
各位大神帮帮忙,我是要做一个留言板用JSP+servlet,可是老师出现这个问题
type Status report
message /CH009/AddMessageServlet
description The requested resource is not available.
Apache Tomcat/7.0.57
以下是我的JSP和servlet代码
<%@ page language="java" import="java.util.*" contentType="text/html" 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>留言板面</title>
</head>
<body background="pic/background.jpg">
<form action="AddMessageServlet" method="post">
留言者:<input type="text" name="author" size="30"/><br>
留言标题:<input type="text" name="title" size="30"/><br>
留言内容:<textarea name="content" rows="8" cols="30"/></textarea>
<p>
<input type="submit" value="提交"/>
<input type="reset" value="重置"/>
<a href="showMessage.jsp">查看留言</a>
</p>
</form>
</body>
</html>
package servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class AddMessageServlet extends HttpServlet {
public AddMessageServlet() {
super();
}
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request,response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String author=new
String(request.getParameter("author").getBytes("ISO-8859-1"),"UTF-8");
String title=new
String(request.getParameter("title").getBytes("ISO-8859-1"),"UTF-8");
String content=new
String(request.getParameter("content").getBytes("ISO-8859-1"),"UTF-8");
SimpleDateFormat format=new
SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String today=format.format(new Date());
MessageBean mm=new MessageBean();
mm.setAuthor(author);
mm.setTitle(title);
mm.setTime(today);
mm.setContent(content);
HttpSession session=request.getSession();
ServletContext scx=session.getServletContext();
ArrayList wordlist=(ArrayList)scx.getAttribute("wordlist");
if(wordlist==null)
wordlist=new ArrayList();
wordlist.add(mm);
scx.setAttribute("wordlist", wordlist);
response.sendRedirect("showMessage.jsp");
}
public void init() throws ServletException {
// Put your code here
}
}
*********************************************************************************************
<%@ page import="servlet.MessageBean" %>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
<base href="<%=basePath%>">
<title>显示留言内容</title>
</head>
<body background="pic/background.jpg">
<%
ArrayList wordlist=(ArrayList)application.getAttribute("wordlist");
if(wordlist==null||wordlist.size()==0)
out.print("没有留言可以显示!");
else{
for(int i=wordlist.size()-1;i>=0;i--){
MessageBean mm=(MessageBean)wordlist.get(i);
%>
留言者:<%=mm.getAuthor() %>
<p>留言时间:<%=mm.getTime() %></p>
<p>留言标题:<%=mm.getTitle() %></p>
<p>留言内容:
<textarea rows="8" cols="30" readonly>
<%=mm.getContent() %>
</textarea>
</p>
<a href="messageBoard.jsp">我要留言</a>
<hr width="90%">
<%
}
}
%>
</body>
</html>
**************************************************************************************************
package servlet;
public class MessageBean {
private String author;
private String title;
private String content;
private String time;
public MessageBean() {
super();
}
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 getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
}