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

求救阿,小弟我用STRUTS开发的时候碰到了java.lang.NullPointerException错误,实在找不出来,求救

2012-03-17 
求救阿,我用STRUTS开发的时候碰到了java.lang.NullPointerException异常,实在找不出来,求救这个事我的JSP

求救阿,我用STRUTS开发的时候碰到了java.lang.NullPointerException异常,实在找不出来,求救
这个事我的JSP请求页面:
<form   action= " <%=path%> %> /AddBookSave.do "   name= "addBook "   method= "post ">
        <table   width= "756 "   height= "138 "   border= "0 ">
                <tr>
                        <td   width= "178 "   height= "39 "> 图书信息添加: </td>
                        <td   width= "197 "> &nbsp; </td>
                        <td   width= "163 "> &nbsp; </td>
                        <td   width= "200 "> &nbsp; </td>
                </tr>
                <tr>
                        <td   height= "18 "> <div   align= "center "> 书名: </div> </td>
                        <td>
                                <label>
                                        <input   type= "text "   name= "name "/>
                                </label>

                        </td>
                        <td> <div   align= "center "> 作者: </div> </td>
                        <td>
                                <label>
                                        <input   type= "text "   name= "author "/>
                                </label>

                        </td>
                </tr>
                <tr>
                        <td   height= "37 "> <div   align= "center "> 出版社: </div> </td>
                        <td>
                                <label>
                                        <input   type= "text "   name= "press "/>


                                </label>

                        </td>
                        <td> <div   align= "center "> 分类: </div> </td>
                        <td>
                                <label> </label>


                                <label>
                                        <select   name= "bookType ">
                                                <option   value= "1 "   selected= "selected "> 计算机 </option>
                                                <option   value= "2 "> 科学 </option>
                                                <option   value= "3 "> 历史 </option>
                                                <option   value= "4 "> 文化 </option>
                                        </select>
                                </label>

                        </td>
                </tr>
                <tr>
                        <td   height= "31 "> <div   align= "center "> 单价:   </div> </td>
                        <td>
                                <label>
                                        <input   type= "text "   name= "price "/>
                                </label>

                        </td>
                        <td> <div   align= "center "> 数量: </div> </td>
                        <td>


                                <label>
                                        <input   type= "text "   name= "count "/>
                                </label>

                        </td>
                </tr>
        </table>
        <br/>
        <table   width= "756 "   border= "0 ">
                <tr>
                        <td   height= "23 "> 图书介绍: </td>
                </tr>
                <tr>
                        <td   height= "164 "> <label>
                                <textarea   name= "textarea "   cols= "105 "   rows= "10 "> </textarea>
                        </label>
                        </td>
                </tr>
        </table>
</form>

这个是FORM:
public   class   BookInfoForm   extends   ActionForm   {
        String   id;
        String   cateid;
        String   bookType;
        String   name;
        String   price;
        String   press;
        String   author;
        String   content;
        String   count;
        Date   regdate   =   null;
        String   sentcount;}//GET和SET方法太长久没有贴出来了,由于是空异常,想看看是不是因为FORM属性不对应。

这个是ACTION   :
public   ActionForward   execute(ActionMapping   actionMapping,
                                                                  ActionForm   actionForm,
                                                                  HttpServletRequest   request,
                                                                  HttpServletResponse   repsonse)   {


                System.out.println( "保存书目信息 ");
                BookInfoForm   form   =   (BookInfoForm)   actionForm;
                DBManager   db   =   new   DBManager();
                db.getConnection();
                db.getStatement();

                BookKindCode   code   =   null;
                String   name   =   form.getName();

                System.out.println( "书名: "   +   name);
                Float   price   =   Float.parseFloat(form.getPrice());
                String   press   =   form.getPress();
                String   author   =   form.getAuthor();
                int   count   =   Integer.parseInt(form.getCateid());
                int   cateid   =   code.getKindCode(form.getBookType());
                String   content   =   form.getContent();
                Date   regDate   =   form.getRegdate();
                System.out.println( " "   +   regDate);
                int   id   =   2;
                int   sentCount   =   2;

                String   sql   =   "insert   into   book(id,cateid,name,price,press,author,content,count,regdate,sentcount)   "   +
                                "values( ' "   +   id   +   " ', ' "   +   cateid   +   " ', ' "   +   name   +   " ', ' "   +   price   +   " ', ' "   +   press   +   " ', ' "   +   author   +   " ', ' "   +   content   +   " ', ' "   +   count   +   " ', ' "   +
                                regDate   +   " ', ' "   +   sentCount   +   " ') ";
                int   i   =   db.executeUpdate(sql);
                if   (i   ==   0)   {
                        return   actionMapping.findForward( "fail ");
                }   else   {
                        return   actionMapping.findForward( "success ");
                }




        }
谢谢了,

[解决办法]
在 <form action= " <%=path%> %> /AddBookSave.do " name= "addBook " method= "post "> 有问题,你改改看:
action=你在配置文件中对应的action的path就行了,
例如: <form action= "AddBookSave.do " name= "addBook " method= "post ">
[解决办法]
看一眼你的getset写对没落.大小写规范没?页面post了不能自动传值那就是你的对应该表单的ActionForm有问题
[解决办法]
<form action= " <%=path%> %> /AddBookSave.do " name= "addBook " method= "post ">
action 里多了“%> ”

热点排行
Bad Request.