Posts

Compile and Run code in assertion in java

Compile and run code using assertion,  Note: The Java 6 compiler will use the assert keyword by default. Unless you tell it otherwise, the compiler will generate an error message if it finds the word assert used as an identifier. However, you can tell the compiler that you're giving it an old piece of code to compile, and that it should pretend to be an old compiler! Here is a code: -------------------------Assertiontest.java---------------------------------------------------------- class AssertionTest{   public static void main(String [] arg){      int num=Integer.parseInt(arg[0]);      assert num>=0 : "The number you have provide by command line                  argument is not a positive number:"+num;      System.out.println("This number is positive:"+num);  // This will execute if number is positive   } } --------------------------------------------...

Limitations of Assertion in Java

Image
Assertions: It give you a way to test your assumptions during development and debugging. They are typically enabled during testing but disabled during deployment. private void numberTest(int num){     if(num>=0){    useNumber(num+a); }else{  // Here it will come only if num<0        System.out.println("This is a negative number:"+num); } } use assert : Suppose number will always be positive, private void numberTest(int num){     assert(num>=0);         // First flavor of assertion useNumber(num+a);        } assert(num>=0):"This is negative number"+num;         // second flavor of assertion      exp1                      exp2 Here this line has tqo expression, exp2 will execute if number is negative and it will print this String message following Asserti...

Upload File using in struts 2

Image
-Use struts2 required lib jar files and see the following files also... 1) Here is the action file.... FileUploadAction.java ------------------------------------------ package com.example.common.action; import java.io.File; import com.opensymphony.xwork2.ActionSupport; public class FileUploadAction extends ActionSupport{ private File fileUpload; private String fileUploadContentType; private String fileUploadFileName; public String getFileUploadContentType() { return fileUploadContentType; } public void setFileUploadContentType(String fileUploadContentType) { this.fileUploadContentType = fileUploadContentType; } public String getFileUploadFileName() { return fileUploadFileName; } public void setFileUploadFileName(String fileUploadFileName) { this.fileUploadFileName = fileUploadFileName; } public File getFileUpload() { return fileUpload; } public void setFileUpload(File fileUpload) { this.fileUpload =...

No result defined for action :Struts 2 exception

Oct 5, 2011 1:03:14 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger warn WARNING: Could not find action or result No result defined for action com.example.user.action.LoginAction and result input at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:363) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:265) at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:249) at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122) at com.opensymphony.xwork2...

Interceptors in Struts 2: See all request parameters before action

Interceptor is a class without state that works like a filter. These are objects that dynamically intercept your defined action invocations. They give the advantage to developer, just define any code which can be executed before the action or after the action. Using interceptor you can prevent the execution of an action. So over all you can say that interceptors provide the interface where you can encapsulate common functionality in a re-usable form for more than one action. Signature:   public interface Interceptor extends Serializable See an example for checking the values in request parameters invoked from a jsp page before going to action::: ************************************************************* package com.example.web.interceptor; import java.util.Iterator; import java.util.Map; import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.interceptor.Interceptor; public class TestActionInterceptor implements Interceptor { /** ...

Assertion in Java: Legal and illegal assert statements

Valid/Invalid Assertion expression   1) assert (x > =0);   2) assert (x > =0): "X is a negative number:"+x;       exp1                exp2 The second expression can be anything that results in a value. Remember, the second expression is used to generate a String message that displays in the stack trace to give you a little more debugging information. It works much like System.out.println() in that you can pass it a primitive or an object, and it will convert it into a String representation. It must resolve to a value! ------------------------------------------------------------------------------------------------------- class AssertTest {          // (for example)   void noReturnValue() { }   int aReturnValue() { return 1; }   void assertTest() {     int x = 1;     boolean b = true;     // the following six are lega...

Page Loading effect using jquery

Image