Actually I am creating an object for a class(Scriptlets in JSP) to run the methods in that class when the jsp is loaded for the first time. Later I will be filling up the fields,once submit button is clicked,the data will be stored in the database and I will redirect the same webpage to make the next entry.
index.jsp
<%
CallClass obj = new CallClass();
UpdateRead upobj = new UpdateRead();
%>
<s:form action=entry>
<s:submit name="submit" value="Submit"/>
</form>
struts.xml
<action name="entry" class="Com.PurchaseEntry" method="getData">
<result>index.jsp</result>
</action>
After inserting the entry into the database it redirects to same index.jsp.
But when loading the same page,it is giving exception that the created instance(Callclass and UpdateRead) the reference created is not nullified! Is it possible to give null values to the same object inside struts action method
public String getData(){
try{
String sql ="insert into database";
st=ob.statementmeth();
boolean b=st.execute(sql);
CallClass obj=null;//Do this assignment affects the index.jsp page's created instance
UpdateRead upobj =null;//Do this assignment affects the index.jsp page's created instance
}
catch(Exception e){
System.out.println("Exception in inserting the data "+e.getMessage());
}
return SUCCESS;
}
Is it possible to reinvoke the same object when the page is loading again after submission.