JSP提交到Servlet出现405错误
这是错误信息typeStatusreportmessageHTTPmethodPOSTisnotsupportedbythisURLdescriptionThespeci...
这是错误信息type Status report
message HTTP method POST is not supported by this URL
description The specified HTTP method is not allowed for the requested resource (HTTP method POST is not supported by this URL).
============================================================================================================
这是JSP页面
<center>
<form action="./servlet/addImages" method="post" enctype="multipart/form-data">
<table width="900" cellspacing="1" bgcolor="#999999">
<tr>
<td height="50" colspan="2" align="center" bgcolor="#FFFFFF">图片添加 </td>
</tr>
<tr>
<td width="200" height="30" bgcolor="#FFFFFF" align="center">图片名称 </td>
<td width="700" bgcolor="#FFFFFF"> <input name="name" type="text" size="50"> </td>
</tr>
<tr>
<td height="30" align="center" bgcolor="#FFFFFF">添加图片 </td>
<td bgcolor="#FFFFFF"> <input name="pic" type="file" size="50"> </td>
</tr>
<tr>
<td height="20" colspan="2" align="center" bgcolor="#FFFFFF">
<input type="submit" value="提交">
<input type="reset" value="重置">
</td>
</tr>
</table> </form>
</center>
============================================================================
下面是Servlet代码
package org.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.PageContext;
import org.lxh.smart.SmartUpload;
public class addImages extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response, PageContext pageContext)
throws ServletException, IOException {
doPost(request,response);
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @param pageContext
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response, PageContext pageContext)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
SmartUpload smartupload = new SmartUpload();
smartupload.initialize(pageContext);
try {
smartupload.upload();
smartupload.save("upload");
} catch (Exception e) {
// TODO: handle exception
}
}
} 展开
message HTTP method POST is not supported by this URL
description The specified HTTP method is not allowed for the requested resource (HTTP method POST is not supported by this URL).
============================================================================================================
这是JSP页面
<center>
<form action="./servlet/addImages" method="post" enctype="multipart/form-data">
<table width="900" cellspacing="1" bgcolor="#999999">
<tr>
<td height="50" colspan="2" align="center" bgcolor="#FFFFFF">图片添加 </td>
</tr>
<tr>
<td width="200" height="30" bgcolor="#FFFFFF" align="center">图片名称 </td>
<td width="700" bgcolor="#FFFFFF"> <input name="name" type="text" size="50"> </td>
</tr>
<tr>
<td height="30" align="center" bgcolor="#FFFFFF">添加图片 </td>
<td bgcolor="#FFFFFF"> <input name="pic" type="file" size="50"> </td>
</tr>
<tr>
<td height="20" colspan="2" align="center" bgcolor="#FFFFFF">
<input type="submit" value="提交">
<input type="reset" value="重置">
</td>
</tr>
</table> </form>
</center>
============================================================================
下面是Servlet代码
package org.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.PageContext;
import org.lxh.smart.SmartUpload;
public class addImages extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response, PageContext pageContext)
throws ServletException, IOException {
doPost(request,response);
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @param pageContext
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response, PageContext pageContext)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
SmartUpload smartupload = new SmartUpload();
smartupload.initialize(pageContext);
try {
smartupload.upload();
smartupload.save("upload");
} catch (Exception e) {
// TODO: handle exception
}
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询