简体   繁体   English

请帮助解决此空指针异常。 该项目涉及struts2,jsp,java和struts.xml

[英]Please help in resolving this null pointer exception. This projct involves with struts2, jsp, java and struts.xml

The following jsp displays 4 text fields from the corresponding data base 以下jsp显示来自相应数据库的4个文本字段

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sj" uri="/struts2-jquery-tags"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<p>This is for fun</p>


<s:form action="eAction" name="eSites">
    <s:textfield value="%{l.Name}" label="Name" id="name" ></s:textfield>
    <s:textfield value="%{l.plan}" label="t Plan" id="plan" ></s:textfield>

</s:form>

<s:form action="updateAction" name="eSite">

<button onclick="output()">Update</button>
<script>
function output(){
         eSite.submit();    
    }
</script>
</s:form>


</body>
</html>

Following is the database: 以下是数据库:

INSERT INTO engagement(PId, S_Id, P_Name, Pa_Plan, Pa_Method, PDate) 
    VALUES(2, 1, 'erferef', 'ergregre', 'egregref', '2012-9-19');

Followign is the struts.xml code. Followign是struts.xml代码。

    <action name="eAction"   class="com.fr.actions.EEngagement">
        <result name ="resultedfunc">/jsp/EParentEngagement.jsp</result> 
    </action>

    <action name="updateAction" class="com.fr.actions.EEngagement" method="update">
        <result name ="UPDATE">/jsp/Engagement.jsp</result>
    </action>

The problem arises is when I give xxx.eAction, I could see 4 text fields with data populated from db. 出现的问题是当我给xxx.eAction时,我可以看到4个文本字段,其中包含从db填充的数据。 After that if I click update button(code for this button is present in jsp file), the url is updateAction.action and I get null pointer exception in the following line. 之后,如果我单击更新按钮(jsp文件中存在此按钮的代码),则该URL为updateAction.action,并且在下一行中得到空指针异常。

        System.out.println(li.gett_Name());

Could some one please resolve this. 有人可以解决这个问题。 I have spent almost 6+ hrs. 我花了将近6个多小时。 I have tried autogenerating getters and setters and refactoring everything. 我尝试过自动生成getter和setter并重构所有内容。 But still I could not figure out. 但是我仍然不知道。 Please Please help me. 请帮帮我。

Looks like below operation missing in your update method 看起来您的更新方法中缺少以下操作

EditParentEngagementDAO editParentEngagementDAO = new EditParentEngagementDAO();
listSiteDetails = editParentEngagementDAO.aSiteIdDetails(getParentengid());

You may need to call this before calling listsitedetails.get.. 您可能需要在调用listsitedetails.get..之前调用listsitedetails.get..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM