急啊老出现The requested resource (/videosite/uploadservlet) is not available.

suansuanok 2011-05-16 12:31:22
一个关于视频上传页面填写信息页面代码是这样的:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body bgcolor="fad400">
<form action="./uploadservlet" method="post" enctype="multipart/form-data" name="form1" id="form1">
<table width="535" border="1" align="center">
<tr>
<td width="230"><div align="right">名称:</div></td>
<td><label>
<input type="text" name="name" id="name" />
</label></td>
</tr>
<tr>
<td><div align="right">作者:</div></td>
<td><label>
<input type="text" name="author" id="author" />
</label></td>
</tr>
<tr>
<td><div align="right">简介:</div></td>
<td><label>
<textarea name="summary" id="summary" cols="45" rows="10"></textarea>
</label></td>
</tr>
<tr>
<td><div align="right">视频文件:</div></td>
<td><label>
<input type="file" name="file" />
</label></td>
</tr>
<tr>
<td height="35"><label>
<div align="right">
<input type="submit" name="button" id="button" value="提交" />
</div>
</label></td>
<td><label>
<input type="reset" name="button2" id="button2" value="重置" />
</label></td>
</tr>
</table>
</form>

</body>
</html>

这个运行时是正常的,然后是编写上传信息处理的程序uploadservlet是
package cn.oioy.servlet;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jspsmart.upload.SmartUpload;

public class UploadServlet extends HttpServlet
{
/**
*
*/
private static final long serialVersionUID = 6401161365045982666L;
private ServletConfig config;

final public void init(ServletConfig config)throws ServletException
{
this.config=config;
}

final public ServletConfig getServletConfig()
{
return config;
}

public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException
{
doPost(request,response);
}

protected void doPost(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException
{
SmartUpload mySmartUpload=new SmartUpload();

try
{
//上传到服务器的路径
String saveDirectory=request.getSession().getServletContext().getRealPath("videos");


//初始化上传组件
mySmartUpload.initialize(config,request,response);
//开始上传数据
mySmartUpload.upload();

//获取name字段信息
String name=(String)mySmartUpload.getRequest().getParameter("name");
//获取author字段信息
String author=(String)mySmartUpload.getRequest().getParameter("author");
//获取summary字段信息
String summary=(String)mySmartUpload.getRequest().getParameter("summary");
//获取上传文件的文件名
String filename=mySmartUpload.getFiles().getFile(0).getFileName();

//保存上传文件到指定目录
mySmartUpload.save(saveDirectory);
String mysqlUrl="jdbc:mysql://127.0.0.0:3306/videosite?useUnicode=true&characterEnc-oding=gb2312";
String mysqldriver="org.gjt.mm.mysql.Driver";
String sql="insert into videos(name,author,summary,videofilename,pubdate)values(?,?,?,?,?)";


java.util.Date d = new java.util.Date();
java.sql.Date pubdate = new java.sql.Date(d.getTime());

Class.forName(mysqldriver);
Connection con = DriverManager.getConnection(mysqlUrl,"root","123");
PreparedStatement pstmt = con.prepareStatement(sql);
//设置各个字段
pstmt.setString(1,name);
pstmt.setString(2,author);
pstmt.setString(3,summary);
pstmt.setString(4,filename);
pstmt.setDate(5,pubdate);

//执行sql语句
pstmt.executeUpdate();
//设置成功标志,后续页面据此知道处理成功
request.setAttribute("flag","ok");
//重定向到结果显示页
request.getRequestDispatcher("submitInfo.jsp").forward(request,response);

}
catch (Exception e)
{
request.setAttribute("flag","error");
request.getRequestDispatcher("submitInfo.jsp").forward(request,response);
e.printStackTrace();
}
}
public void destroy()
{}
}


这个java一开始说api过时了不支持getrealpath我就给改成了了request.getSession().getServletContext().getRealPath("videos");然后出了个UploadServlet.class文件拖到了
E:\apache-tomcat-6.0.30\webapps\videosite\WEB-INF\classes\cn\oioy\servlet里
然后就是注册。。。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Web-app PUBLIC"-//Sun Microsystem,Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/Web-app_2_2.dtd">
<web-app>
<servlet>
<servlet-name>uploadservlet</servlet-name>
<servlet-class>cn.oioy.servlet.UploadServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>uploadservlet</servlet-name>
<url-pattern>/uploadservlet</url-pattern>
</servlet-mapping>
</web-app>

在这个文件夹里头E:\apache-tomcat-6.0.30\webapps\videosite\WEB-INF。。。。html的成功,填信息。。上传确定。。找不到页面失败。。错误信息是:错误404type Status report

message /videosite/uploadservlet

description The requested resource (/videosite/uploadservlet) is not available.

崩溃了。。。啊啊求正解
...全文
284 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
YuqiSun 2012-02-15
  • 打赏
  • 举报
回复
我也遇到过,action="./uploadservlet" 把这个路径改改试试,用绝对路径试一下
huanyinglizzy 2011-09-05
  • 打赏
  • 举报
回复
怎么办啊,我和你一样的问题。求解
suansuanok 2011-05-16
  • 打赏
  • 举报
回复
试了。。没用ing。。。。。这写法应该没错吧
错误依旧是The requested resource (/videosite/uploadservlet) is not available.
我是风 2011-05-16
  • 打赏
  • 举报
回复
<form action="./uploadservlet" method="post" enctype="multipart/form-data" name="form1" id="form1">

改成/uploadservlet试试。。。

51,411

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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