首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

这个servlet的路径为什么总是找不到?那位老大指点一下?解决办法

2012-01-19 
这个servlet的路径为什么总是找不到????那位老大指点一下?1.jsp页面:!DOCTYPEhtmlPUBLIC-//W3C//DTDHTML

这个servlet的路径为什么总是找不到????那位老大指点一下?
1.jsp页面:

<!DOCTYPE   html   PUBLIC   "-//W3C//DTD   HTML   4.01   Transitional//EN ">
 
<%@   page   language= "java "   contentType= "text/html;charset=GB2312 "%>
<html>
    <head>      
        <title> logon.jsp </title>  
        <style   type= "text/css ">
<!--
@import   url( "../bbs/pic/OSX/OSX.css ");
-->
        </style>
    </head>
   
    <body>
    <form   name= "form1 "   method= "post "   action= "save ">
    <table   width= "100% "   height= "142 "   border= "1 ">
        <tr   align= "center ">
            <td   colspan= "2 "> 美时美刻 </td>
        </tr>
        <tr>
            <td   width= "42% "> 型号*: </td>
            <td   width= "58% "> <input   type= "text "   name= "id "> </td>
        </tr>
        <tr>
            <td> 物品名称: </td>
            <td> <input   type= "text "   name= "name "> </td>
        </tr>
                <tr>
            <td> 进货人: </td>
            <td> <input   type= "text "   name= "nabuypersonme "> </td>
        </tr>
        <tr>
            <td> 买出人: </td>
            <td> <input   type= "text "   name= "sellperson "> </td>
        </tr>
                <tr>
            <td> 进货时间: </td>
            <td> <input   type= "text "   name= "buytime "> </td>
        </tr>
                        <tr>
            <td> 买出时间: </td>
            <td> <input   type= "text "   name= "selltime "> </td>
        </tr>
                                <tr>
            <td> 顾客姓名: </td>
            <td> <input   type= "text "   name= "gouwurenname "> </td>
        </tr>


        <tr>
            <td> 顾客级别: </td>
            <td> <input   type= "text "   name= "level "> </td>
        </tr>
                <tr>
            <td> 折扣: </td>
            <td> <input   type= "text "   name= "discount "> </td>
        </tr>
<tr   align= "center ">
            <td   colspan= "2 ">             <input   name= "submit "   type= "submit "   id= "submit "   value= "保存 "> </td>
        </tr>
    </table>        
    </form>    
    </body>

</html>


2.servlet:

package   com.cn;
import   com.cn.DataStore;
import   java.io.IOException;

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   save   extends   HttpServlet   {

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

HttpSession   session   =   request.getSession();

String   id   =   request.getParameter( "id ");
  String   name   =   request.getParameter( "name ");
String   buyperson   =   request.getParameter( "buyperson ");
String   sellperson   =   request.getParameter( "sellperson ");
String   buytime   =   request.getParameter( "buytime ");
String   selltime   =   request.getParameter( "selltime ");
String   gouwurenname   =   request.getParameter( "gouwurenname ");
String   level   =   request.getParameter( "level ");
String   discount   =   request.getParameter( "discount ");

if(   (id   !=   null))
{String   sqls=null;
StringBuffer   sql   =   new   StringBuffer   ();
sql.append( "   insert   into   chest   (   "+ "id,name,buyperson,sellperson,buytime,selltime,gouwurenname,level,discount   ) "
+ "values( ' "+id+ " ', ' "+name+ " ', ' "+buyperson+ " ', ' "+sellperson+ " ', ' "+buytime+ " ', ' "+selltime+ " ', ' "+gouwurenname+ " ', ' "+level+ " ', ' "+discount+ " ') ");
sqls=sql.toString();
System.out.println(sql);
DataStore   dd   =   null;

dd.execute(sqls);

}

String   logon_suc=   "success.jsp ";
response.sendRedirect(logon_suc);


}

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


3.web.xml  

<?xml   version= "1.0 "   encoding= "UTF-8 "?>

<web-app   version= "2.4 "  
xmlns= "http://java.sun.com/xml/ns/j2ee "  
xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance "  
xsi:schemaLocation= "http://java.sun.com/xml/ns/j2ee  
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd ">
<welcome-file-list>
<welcome-file> logon.jsp </welcome-file>
</welcome-file-list>
    <servlet>
        <description> This   is   the   description   of   my   J2EE   component </description>
        <display-name> This   is   the   display   name   of   my   J2EE   component </display-name>
        <servlet-name> save </servlet-name>
        <servlet-class> com.cn.save </servlet-class>
    </servlet>    
    <servlet-mapping>
        <servlet-name> save </servlet-name>
        <url-pattern> /save </url-pattern>
    </servlet-mapping>
</web-app>    

这样设计为什么总是找不到servlet的路径,总是显示
HTTP   Status   404   -   /meishimeike/save

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

type   Status   report

message   /meishimeike/save

description   The   requested   resource   (/meishimeike/save)   is   not   available.


[解决办法]
试试看/save
[解决办法]
楼上说的还不行的话
在 <html> 上一行加上这个
<%
String path = request.getContextPath();
String basePath = request.getScheme()+ ":// "+request.getServerName()+ ": "+request.getServerPort()+path+ "/ ";
%>
再在 <head> </head> 中间加
<base href= " <%=basePath%> ">
[解决办法]
<servlet-mapping>
<servlet-name> save </servlet-name>
<url-pattern> /meishimeike/save </url-pattern>
</servlet-mapping>
看看如何!404错位一般是你的URL-PATTERN不对,
如果不行就试试这样:
<servlet-mapping>
<servlet-name> save </servlet-name>
<url-pattern> *.save </url-pattern>
</servlet-mapping>



[解决办法]
没错。
[解决办法]
web.xml的问题

热点排行