-1

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.

Mathu
  • 84
  • 1
  • 12
  • merely same to this concept but I am trying in WebApplication http://stackoverflow.com/questions/16359662/destroy-instance-of-class-then-create-instance-of-it-again – Mathu Feb 03 '14 at 12:18
  • Create a new instance again for that class and do redirect to the same page – Radhamani Muthusamy Feb 03 '14 at 12:18
  • Don't use scriptlets. Ever. http://stackoverflow.com/questions/3177733/how-to-avoid-java-code-in-jsp-files – JB Nizet Feb 03 '14 at 12:22
  • The question is not clear, and there's no code. But one thing is for sure, making one page handle every operation with a mess of if's is a bad idea. – developerwjk Feb 03 '14 at 19:22
  • I have added the snippets. To make the question clear I have referred the url- (My first comment) which is related to my case But I am expecting in Web Application – Mathu Feb 04 '14 at 05:00

1 Answers1

0

I resolved this issue, just by two smiliar pages in the application, one (jsp) will be invoked for the first time which actually contains this particular codings

<% CallClass obj = new CallClass();
    UpdateRead upobj = new UpdateRead(); %>

And while submitting the form it will directed to the action class where I have instantiated the same, through which we can avoid using the above coding in another jsp

Flow will continue by presenting the second jsp in the browser,Flow of execution also doesn't get break

Mathu
  • 84
  • 1
  • 12