EzDevInfo.com

struts2 interview questions

Top struts2 frequently asked interview questions

What's the difference between # , % and $ signs in Struts tags?

I'm working with Struts2 and when I'm accessing value stack variables I don't know whether to use % or # or $. I try all of them until I find the correct one.

Can Anybody Explain what is the difference between these?


Source: (StackOverflow)

Action redirect in struts.xml

Can I redirect to another action from within a struts actions ? So the result of an action is another action i.e - here is a snippet of struts.xml

    <action name="newRedirect" >
        <result>formsearch</result>
    </action>

    <action name="formsearch" class="com.event.action.SearchForm"
    method="execute">
        <result name="success">/form.jsp</result>
    </action>

Thanks


Source: (StackOverflow)

Advertisements

Struts2: Why to extend ActionSupport class?

I am a beginner to Struts2. Please tell me why to extend ActionSupport class? (When one doesn't have the requirement of validation or internationalization)

Are there any other benefits provided by extending ActionSupport class?


Source: (StackOverflow)

Download a file by jQuery.Ajax

I have a Struts2 action in the server side for file downloading.

<action name="download" class="com.xxx.DownAction">
    <result name="success" type="stream">
        <param name="contentType">text/plain</param>
        <param name="inputName">imageStream</param>
        <param name="contentDisposition">attachment;filename={fileName}</param>
        <param name="bufferSize">1024</param>
    </result>
</action>

However when I call the action using the jQuery:

$.post(
  "/download.action",{
    para1:value1,
    para2:value2
    ....
  },function(data){
      console.info(data);
   }
);

in Firebug I see the data is retreived with the Binary stream. I wonder how to open the file downloading window with which the user can save the file locally?


Source: (StackOverflow)

How to deploy war files into cPanel and remove the project name?

I need to run my Java application on cPanel. I have successfully installed Tomcat,

I can run my application by copying war file into my www folder but the problem is that it shows the Project name (war file name) in the address, I need to know how to remove that, so users can access www.example.com rather than www.example.com/MyProject/index.jsp?


Source: (StackOverflow)

Serve static files (JavaScript) with Struts 2

I want to put some JavaScript files in one of my packages and make Struts serve them like /struts/js/foo.js

Struts does that for files in 'template' package (that's where jQuery plugin's files are located, guarded by struts.ui.templateDir option). However I want to put those files into another package; If I redefine struts.ui.templateDir then struts ceases working because it can't find its templates.

So the question is: How to tell Struts to serve files in org.foo.some.package.js as /struts/js/whatever.js?


Source: (StackOverflow)

Difference between servlet/servlet-mapping and filter/filter-mapping?

As part of exploring/learning Struts2, JSP and Servlets, I see from here and there that servlets and servlets-mapping can be used in web.xml. However, Struts2 mentions filters and filter-mapping too for web.xml.

What is the difference between both? Are these mutually exclusive? When should I use which and why? Can someone clarify the concepts? Thanks.

CLARIFICATION

I just got to understand that I needed to understand how Struts2 and Servlets are related: http://www.coderanch.com/t/57899/Struts/Difference-between-servlet-struts


Source: (StackOverflow)

Format number in Struts 2 tag

I would like to format number displayed by <s:property value="summary.total"/> tag in Struts 2. There is a double value. How can I do that? Should I use OGNL?

Or maybe I must use <s:text/> tag and define my format in resuource file?


Source: (StackOverflow)

Slow to start after upgraded to Spring 3

I use Struts2 and my application has thousands of action classes managed by Spring. I used Spring 2.5.6 before and my application starts quickly. But when I changed Spring to 3.0. I got a extremely slow start up of Tomcat. For each action class, I got the following debug message from Spring:

DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public java.util.List 

Almost each method of each action class was printed such message above. It is the reason why application spent so many time to start up.

Below is a snapshot from my spring xml, for your reference.

<aop:config proxy-target-class="true"/> <!-- No matter true of false, the problem remains -->
<context:component-scan base-package="com.mycom" scoped-proxy="targetClass"/>

Let me append the full debug message from Spring showing the progress of creating a bean:

2010-01-19 17:07:32,786 [main] DEBUG (DefaultSingletonBeanRegistry.java:214) - Creating shared instance of singleton bean 'CL04001Action'
2010-01-19 17:07:32,786 [main] DEBUG (AbstractAutowireCapableBeanFactory.java:424) - Creating instance of bean 'CL04001Action'
2010-01-19 17:07:32,787 [main] DEBUG (AbstractAutowireCapableBeanFactory.java:498) - Eagerly caching bean 'CL04001Action' to allow for resolving potential circular references
2010-01-19 17:07:32,787 [main] DEBUG (Cglib2AopProxy.java:150) - Creating CGLIB2 proxy: target source is SimpleBeanTargetSource for target bean 'scopedTarget.CL04001Action' of type [com.mycom.action.cl.CL04001Action]
2010-01-19 17:07:32,790 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public com.mycom.action.cl.context.CL04001Context com.mycom.action.cl.CL04001Action.getContext()
2010-01-19 17:07:32,791 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public void com.mycom.action.cl.CL04001Action.setContext(com.mycom.action.cl.context.CL04001Context)
2010-01-19 17:07:32,792 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public java.lang.String com.mycom.action.cl.CL04001Action.CL04001Main()
2010-01-19 17:07:32,792 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public int com.mycom.action.cl.CL04001Action.getCounter()
2010-01-19 17:07:32,792 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public void com.mycom.action.cl.CL04001Action.setCounter(int)
2010-01-19 17:07:32,793 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public java.lang.String com.mycom.action.cl.CL04001Action.cl04001MainPage()
2010-01-19 17:07:32,793 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public java.lang.String com.mycom.action.cl.CL04001Action.cl04001Permit()
2010-01-19 17:07:32,793 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public java.lang.String com.mycom.action.cl.CL04001Action.cl04001PermitPage()
2010-01-19 17:07:32,794 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public java.lang.String com.mycom.action.cl.CL04001Action.cl03001Confirm() throws java.lang.Exception
2010-01-19 17:07:32,794 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public java.lang.String com.mycom.action.cl.CL04001Action.cl03001Refuse()
2010-01-19 17:07:32,794 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public com.mycom.model.cl.CL04001Model com.mycom.action.cl.CL04001Action.getModel()
2010-01-19 17:07:32,795 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public void com.mycom.action.cl.CL04001Action.setModel(com.mycom.model.cl.CL04001Model)
2010-01-19 17:07:32,795 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: protected java.lang.Object com.mycom.core.struts2.action.DefaultEsoafAction.get(java.lang.String)
2010-01-19 17:07:32,795 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public java.lang.String com.mycom.core.struts2.action.DefaultEsoafAction.getLanguage()
2010-01-19 17:07:32,796 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: protected void com.mycom.core.struts2.action.DefaultEsoafAction.set(java.lang.String,java.lang.Object)
2010-01-19 17:07:32,796 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public java.lang.String com.mycom.core.struts2.action.DefaultEsoafAction.getCountry()
2010-01-19 17:07:32,797 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public java.lang.String com.mycom.core.struts2.action.DefaultEsoafAction.getSessionId()
2010-01-19 17:07:32,797 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public com.mycom.core.context.AppContext com.mycom.core.struts2.action.DefaultEsoafAction.getAppContext()
2010-01-19 17:07:32,797 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public java.lang.String com.mycom.core.struts2.action.DefaultEsoafAction.loadMessage(java.lang.String,java.lang.String[])
2010-01-19 17:07:32,798 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public java.lang.String com.mycom.core.struts2.action.DefaultEsoafAction.loadMessage(java.lang.String)
2010-01-19 17:07:32,798 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public com.mycom.core.context.SystemInfo com.mycom.core.struts2.action.DefaultEsoafAction.getSystemInfo()
2010-01-19 17:07:32,798 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public void com.mycom.core.struts2.action.DefaultEsoafAction.setSystemInfo(com.mycom.core.context.SystemInfo)
2010-01-19 17:07:32,799 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public void com.mycom.core.struts2.action.DefaultEsoafAction.setAppContext(com.mycom.core.context.AppContext)
2010-01-19 17:07:32,807 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: protected void com.mycom.core.struts2.action.DefaultEsoafAction.setGlobalSession(java.lang.String,java.lang.Object)
2010-01-19 17:07:32,807 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: protected java.lang.Object com.mycom.core.struts2.action.DefaultEsoafAction.getGlobalSession(java.lang.String)
2010-01-19 17:07:32,812 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public void com.mycom.core.struts2.action.DefaultEsoafAction.handleEsoafException(com.mycom.core.exception.DefaultEsoafException,com.mycom.core.struts2.action.DefaultEsoafAction$EType,java.lang.String) throws java.lang.RuntimeException
2010-01-19 17:07:32,813 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public void com.mycom.core.struts2.action.DefaultEsoafAction.handleEsoafException(com.mycom.core.exception.DefaultEsoafException)
2010-01-19 17:07:32,813 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public void com.mycom.core.struts2.action.DefaultEsoafAction.setCountry(java.lang.String)
2010-01-19 17:07:32,814 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public java.lang.String com.mycom.core.struts2.action.DefaultEsoafAction.getSessionTimeoutDuration()
2010-01-19 17:07:32,814 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public void com.mycom.core.struts2.action.DefaultEsoafAction.setJson(java.lang.String)
2010-01-19 17:07:32,815 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public com.mycom.core.model.GeneralModel com.mycom.core.struts2.action.DefaultEsoafAction.getGeneralModel()
2010-01-19 17:07:32,816 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public void com.mycom.core.struts2.action.DefaultEsoafAction.setInit(boolean)
2010-01-19 17:07:32,817 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: protected java.util.Map com.mycom.core.struts2.action.DefaultEsoafAction.initTransacitonSession()
2010-01-19 17:07:32,818 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public void com.mycom.core.struts2.action.DefaultEsoafAction.setInvalidateSession(boolean)
2010-01-19 17:07:32,818 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public boolean com.mycom.core.struts2.action.DefaultEsoafAction.getInvalidSession()
2010-01-19 17:07:32,819 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public java.lang.String com.mycom.core.struts2.action.DefaultEsoafAction.getJson()
2010-01-19 17:07:32,820 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public void com.mycom.core.struts2.action.DefaultEsoafAction.changeLocale()
2010-01-19 17:07:32,821 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public void com.mycom.core.struts2.action.DefaultEsoafAction.setGeneralModel(com.mycom.core.model.GeneralModel)
2010-01-19 17:07:32,822 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public void com.mycom.core.struts2.action.DefaultEsoafAction.setLanguage(java.lang.String)
2010-01-19 17:07:32,823 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public java.util.List com.mycom.core.struts2.action.DefaultEsoafAction.buildPageList(int)
2010-01-19 17:07:32,828 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public com.mycom.core.struts2.interceptor.Category com.mycom.core.struts2.action.DefaultEsoafAction.getCatetory()
2010-01-19 17:07:32,829 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public java.lang.Object com.opensymphony.xwork2.ActionSupport.clone() throws java.lang.CloneNotSupportedException
2010-01-19 17:07:32,830 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public void com.opensymphony.xwork2.ActionSupport.validate()
2010-01-19 17:07:32,831 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public java.lang.String com.opensymphony.xwork2.ActionSupport.execute() throws java.lang.Exception
2010-01-19 17:07:32,845 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public void com.opensymphony.xwork2.ActionSupport.pause(java.lang.String)
2010-01-19 17:07:32,846 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public java.util.Locale com.opensymphony.xwork2.ActionSupport.getLocale()
2010-01-19 17:07:32,846 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public java.lang.String com.opensymphony.xwork2.ActionSupport.input() throws java.lang.Exception
2010-01-19 17:07:32,847 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public void com.opensymphony.xwork2.ActionSupport.addActionError(java.lang.String)
2010-01-19 17:07:33,251 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public void com.opensymphony.xwork2.ActionSupport.setActionErrors(java.util.Collection)
2010-01-19 17:07:33,252 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public java.util.Collection com.opensymphony.xwork2.ActionSupport.getActionErrors()
2010-01-19 17:07:33,252 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public void com.opensymphony.xwork2.ActionSupport.setActionMessages(java.util.Collection)
2010-01-19 17:07:33,252 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public java.util.Collection com.opensymphony.xwork2.ActionSupport.getActionMessages()
2010-01-19 17:07:33,253 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public java.util.Collection com.opensymphony.xwork2.ActionSupport.getErrorMessages()
2010-01-19 17:07:33,253 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public java.util.Map com.opensymphony.xwork2.ActionSupport.getErrors()
2010-01-19 17:07:33,253 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public void com.opensymphony.xwork2.ActionSupport.setFieldErrors(java.util.Map)
2010-01-19 17:07:33,254 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public java.util.Map com.opensymphony.xwork2.ActionSupport.getFieldErrors()
2010-01-19 17:07:33,254 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public boolean com.opensymphony.xwork2.ActionSupport.hasKey(java.lang.String)
2010-01-19 17:07:33,254 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public java.lang.String com.opensymphony.xwork2.ActionSupport.getText(java.lang.String,java.lang.String[])
2010-01-19 17:07:33,255 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public java.lang.String com.opensymphony.xwork2.ActionSupport.getText(java.lang.String)
2010-01-19 17:07:33,255 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public java.lang.String com.opensymphony.xwork2.ActionSupport.getText(java.lang.String,java.lang.String)
2010-01-19 17:07:33,255 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public java.lang.String com.opensymphony.xwork2.ActionSupport.getText(java.lang.String,java.lang.String,java.lang.String)
2010-01-19 17:07:33,256 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public java.lang.String com.opensymphony.xwork2.ActionSupport.getText(java.lang.String,java.util.List)
2010-01-19 17:07:33,256 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public java.lang.String com.opensymphony.xwork2.ActionSupport.getText(java.lang.String,java.lang.String,java.util.List)
2010-01-19 17:07:33,256 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public java.lang.String com.opensymphony.xwork2.ActionSupport.getText(java.lang.String,java.lang.String,java.lang.String[])
2010-01-19 17:07:33,257 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public java.lang.String com.opensymphony.xwork2.ActionSupport.getText(java.lang.String,java.lang.String,java.util.List,com.opensymphony.xwork2.util.ValueStack)
2010-01-19 17:07:33,257 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public java.lang.String com.opensymphony.xwork2.ActionSupport.getText(java.lang.String,java.lang.String,java.lang.String[],com.opensymphony.xwork2.util.ValueStack)
2010-01-19 17:07:33,258 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public java.util.ResourceBundle com.opensymphony.xwork2.ActionSupport.getTexts()
2010-01-19 17:07:33,258 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public java.util.ResourceBundle com.opensymphony.xwork2.ActionSupport.getTexts(java.lang.String)
2010-01-19 17:07:33,258 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public void com.opensymphony.xwork2.ActionSupport.addActionMessage(java.lang.String)
2010-01-19 17:07:33,259 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public void com.opensymphony.xwork2.ActionSupport.addFieldError(java.lang.String,java.lang.String)
2010-01-19 17:07:33,259 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public java.lang.String com.opensymphony.xwork2.ActionSupport.doDefault() throws java.lang.Exception
2010-01-19 17:07:33,259 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public boolean com.opensymphony.xwork2.ActionSupport.hasActionErrors()
2010-01-19 17:07:33,260 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public boolean com.opensymphony.xwork2.ActionSupport.hasActionMessages()
2010-01-19 17:07:33,260 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public boolean com.opensymphony.xwork2.ActionSupport.hasErrors()
2010-01-19 17:07:33,260 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public boolean com.opensymphony.xwork2.ActionSupport.hasFieldErrors()
2010-01-19 17:07:33,261 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public void com.opensymphony.xwork2.ActionSupport.clearFieldErrors()
2010-01-19 17:07:33,261 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public void com.opensymphony.xwork2.ActionSupport.clearActionErrors()
2010-01-19 17:07:33,261 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public void com.opensymphony.xwork2.ActionSupport.clearMessages()
2010-01-19 17:07:33,262 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public void com.opensymphony.xwork2.ActionSupport.clearErrors()
2010-01-19 17:07:33,262 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public void com.opensymphony.xwork2.ActionSupport.clearErrorsAndMessages()
2010-01-19 17:07:33,262 [main] DEBUG (Cglib2AopProxy.java:753) - Found finalize() method - using NO_OVERRIDE
2010-01-19 17:07:33,263 [main] DEBUG (Cglib2AopProxy.java:770) - Found 'hashCode' method: public native int java.lang.Object.hashCode()
2010-01-19 17:07:33,263 [main] DEBUG (Cglib2AopProxy.java:765) - Found 'equals' method: public boolean java.lang.Object.equals(java.lang.Object)
2010-01-19 17:07:33,263 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public java.lang.String java.lang.Object.toString()
2010-01-19 17:07:33,264 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public abstract java.lang.Object org.springframework.aop.scope.ScopedObject.getTargetObject()
2010-01-19 17:07:33,264 [main] DEBUG (Cglib2AopProxy.java:802) - Unable to apply any optimisations to advised method: public abstract void org.springframework.aop.scope.ScopedObject.removeFromScope()
2010-01-19 17:07:33,264 [main] DEBUG (Cglib2AopProxy.java:759) - Method is declared on Advised interface: public abstract int org.springframework.aop.framework.Advised.indexOf(org.aopalliance.aop.Advice)
2010-01-19 17:07:33,265 [main] DEBUG (Cglib2AopProxy.java:759) - Method is declared on Advised interface: public abstract int org.springframework.aop.framework.Advised.indexOf(org.springframework.aop.Advisor)
2010-01-19 17:07:33,265 [main] DEBUG (Cglib2AopProxy.java:759) - Method is declared on Advised interface: public abstract boolean org.springframework.aop.framework.Advised.isFrozen()
2010-01-19 17:07:33,265 [main] DEBUG (Cglib2AopProxy.java:759) - Method is declared on Advised interface: public abstract org.springframework.aop.TargetSource org.springframework.aop.framework.Advised.getTargetSource()
2010-01-19 17:07:33,266 [main] DEBUG (Cglib2AopProxy.java:759) - Method is declared on Advised interface: public abstract void org.springframework.aop.framework.Advised.addAdvisor(org.springframework.aop.Advisor) throws org.springframework.aop.framework.AopConfigException
2010-01-19 17:07:33,266 [main] DEBUG (Cglib2AopProxy.java:759) - Method is declared on Advised interface: public abstract void org.springframework.aop.framework.Advised.addAdvisor(int,org.springframework.aop.Advisor) throws org.springframework.aop.framework.AopConfigException
2010-01-19 17:07:33,266 [main] DEBUG (Cglib2AopProxy.java:759) - Method is declared on Advised interface: public abstract void org.springframework.aop.framework.Advised.setTargetSource(org.springframework.aop.TargetSource)
2010-01-19 17:07:33,267 [main] DEBUG (Cglib2AopProxy.java:759) - Method is declared on Advised interface: public abstract void org.springframework.aop.framework.Advised.setPreFiltered(boolean)
2010-01-19 17:07:33,267 [main] DEBUG (Cglib2AopProxy.java:759) - Method is declared on Advised interface: public abstract boolean org.springframework.aop.framework.Advised.isProxyTargetClass()
2010-01-19 17:07:33,267 [main] DEBUG (Cglib2AopProxy.java:759) - Method is declared on Advised interface: public abstract void org.springframework.aop.framework.Advised.setExposeProxy(boolean)
2010-01-19 17:07:33,268 [main] DEBUG (Cglib2AopProxy.java:759) - Method is declared on Advised interface: public abstract boolean org.springframework.aop.framework.Advised.isExposeProxy()
2010-01-19 17:07:33,268 [main] DEBUG (Cglib2AopProxy.java:759) - Method is declared on Advised interface: public abstract void org.springframework.aop.framework.Advised.addAdvice(org.aopalliance.aop.Advice) throws org.springframework.aop.framework.AopConfigException
2010-01-19 17:07:33,268 [main] DEBUG (Cglib2AopProxy.java:759) - Method is declared on Advised interface: public abstract void org.springframework.aop.framework.Advised.addAdvice(int,org.aopalliance.aop.Advice) throws org.springframework.aop.framework.AopConfigException
2010-01-19 17:07:33,269 [main] DEBUG (Cglib2AopProxy.java:759) - Method is declared on Advised interface: public abstract boolean org.springframework.aop.framework.Advised.isPreFiltered()
2010-01-19 17:07:33,269 [main] DEBUG (Cglib2AopProxy.java:759) - Method is declared on Advised interface: public abstract java.lang.Class[] org.springframework.aop.framework.Advised.getProxiedInterfaces()
2010-01-19 17:07:33,269 [main] DEBUG (Cglib2AopProxy.java:759) - Method is declared on Advised interface: public abstract boolean org.springframework.aop.framework.Advised.isInterfaceProxied(java.lang.Class)
2010-01-19 17:07:33,270 [main] DEBUG (Cglib2AopProxy.java:759) - Method is declared on Advised interface: public abstract org.springframework.aop.Advisor[] org.springframework.aop.framework.Advised.getAdvisors()
2010-01-19 17:07:33,270 [main] DEBUG (Cglib2AopProxy.java:759) - Method is declared on Advised interface: public abstract void org.springframework.aop.framework.Advised.removeAdvisor(int) throws org.springframework.aop.framework.AopConfigException
2010-01-19 17:07:33,270 [main] DEBUG (Cglib2AopProxy.java:759) - Method is declared on Advised interface: public abstract boolean org.springframework.aop.framework.Advised.removeAdvisor(org.springframework.aop.Advisor)
2010-01-19 17:07:33,271 [main] DEBUG (Cglib2AopProxy.java:759) - Method is declared on Advised interface: public abstract boolean org.springframework.aop.framework.Advised.replaceAdvisor(org.springframework.aop.Advisor,org.springframework.aop.Advisor) throws org.springframework.aop.framework.AopConfigException
2010-01-19 17:07:33,271 [main] DEBUG (Cglib2AopProxy.java:759) - Method is declared on Advised interface: public abstract boolean org.springframework.aop.framework.Advised.removeAdvice(org.aopalliance.aop.Advice)
2010-01-19 17:07:33,271 [main] DEBUG (Cglib2AopProxy.java:759) - Method is declared on Advised interface: public abstract java.lang.String org.springframework.aop.framework.Advised.toProxyConfigString()
2010-01-19 17:07:33,272 [main] DEBUG (Cglib2AopProxy.java:759) - Method is declared on Advised interface: public abstract java.lang.Class org.springframework.aop.TargetClassAware.getTargetClass()
2010-01-19 17:07:33,372 [main] DEBUG (AbstractBeanFactory.java:241) - Returning cached instance of singleton bean 'org.springframework.transaction.config.internalTransactionAdvisor'
2010-01-19 17:07:33,373 [main] DEBUG (AbstractAutowireCapableBeanFactory.java:452) - Finished creating instance of bean 'CL04001Action'

Source: (StackOverflow)

Where to put struts.xml

With Struts2 we have to have struts.xml in the class path, so it no longer works to have it under WEB-INF. So the way I got my project to deploy was to stick it under WEB-INF/classes and have it include ../struts2.xml

2 Problems:

  1. Eclipse cleans out the classes folder when I do a rebuild, so it deletes struts.xml
  2. Eclipse doesn't show the classes folder in my project browser, so its a poor place to stick config files in the first place.

How are you Struts2 Eclipse developers doing this?


Source: (StackOverflow)

Deploy Java Web application on Amazon Cloud

I have a web application developed with Struts2, JSP, JPA, Spring and MySql. I want to move this application to Amazon Cloud. I have not done a cloud deployment before or know how to do it. Can anyone help me on a step by step process or a procedure to follow or a document that will guide me in doing this. Thanks for your help.


Source: (StackOverflow)

Getting a 'No thread-bound request found' error from spring in my web app

I'm getting a 'No thread-bound request found' error in my web app and hoping to get some help. I'm trying to use struts2 + spring + hibernate, and use spring to manage the hibernate session factory, and inject hibernate sessions into my struts actions. I hope that made sense. When the app starts up, there are no errors, but when i make the first web request it bombs out with the 'No thread-bound request found' error. Here's my spring config:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
  <bean id="hibernateSessionFactory" scope="singleton"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="configLocation" value="classpath:hibernate.cfg.xml" />
  </bean>
  <bean id="hibernateSession" factory-bean="hibernateSessionFactory"
    factory-method="openSession" destroy-method="close" scope="request" class="org.hibernate.Session" />
</beans>

Here's my action:

package actions.events;
import org.hibernate.Session;

public class Listing {
  Session session;
  public void setHibernateSession(Session value) throws Exception
  {
    session = value;
  }

  public String execute() {
    return "success";
  }
}

My only lead is that if i remove the 'setHibernateSession' function above, i don't get the error because presumably spring doesn't bother creating a session if the action doesn't need one (lazy instantiation).

And here's the exception:

Unable to instantiate Action, actions.events.Listing, defined for 'Listing' in namespace '/events'Error creating bean with name 'hibernateSession': Scope 'request' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:307)
com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:388)
com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:187)
org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)
org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:47)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:478)
org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
com.opensymphony.sitemesh.webapp.SiteMeshFilter.obtainContent(SiteMeshFilter.java:129)
com.opensymphony.sitemesh.webapp.SiteMeshFilter.doFilter(SiteMeshFilter.java:77)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
java.lang.Thread.run(Unknown Source)

Oh and the kicker is that my web.xml does have the necessary context listener, so the http request should be recognised by struts:

<?xml version="1.0" encoding="UTF-8"?>
<web-app ...
  ...
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  ...
</web-app>

Source: (StackOverflow)

OSGi - How mature is this technology?

I have a requirement where I need to share some web resources (jsp, html, js, images, css etc.) across different Spring based Struts 2 applications. And seems like OSGi can be used to achieve this?

  • Can some one give some pointers on how to achieve this with OSGi?
  • And secondly I want to know is OSGi mature enough to be used in production applications?

Thanks in advance!

EDIT: I went through this post and seems like people are able to share a web bundle across web applications. The only difference is that they did it with Spring MVC. I want to know whether this can be achieved with Struts2 applications also?

EDIT 2: I am basically little unclear about the following:

  • Will the 'shareable-bundle' (containing the web resources to be shared) be a .war packaged. If yes, then from where will the final web context be formed since this bundle is again to be shared with the main 'web' application? I am expecting the final web context to be formed out of the merging of the 'shareable-bundle' and the 'main' web application. Will it happen automatically? Any ideas?

Source: (StackOverflow)

applicationContext.xml with datasource or hibernate.cfg.xml. Difference?

Want to clear some confusion. I have applicationContext.xml.

Question 1: Whats the difference between 1 & 2. Are they both same with different approach?

Question 2:

I asked question on Spring forum regarding some problem. Onething he mentioned about pooling is below

if you need/want to use the internal connection pooling for hibernate I would advice against it and simply configure a datasource which supports connection pooling and inject that into your sessionfactorybean.

internal connection pooling for hibernate = This is number 2 below. Right?

simply configure a datasource which supports connection pooling and inject that into your sessionfactorybean = This is number 1 below. right?

1# -

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="${jdbc.driverClassName}"/>
        <property name="url" value="${jdbc.url}"/>
        <property name="username" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
        <property name="maxActive" value="100"/>
        <property name="maxIdle" value="30"/>
        <property name="maxWait" value="16000"/>
        <property name="minIdle" value="0"/>
    </bean>

 <!-- Hibernate SessionFactory -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="annotatedClasses">
            <list>
                <value>com.mkyong.customer.model.Customer</value>
            </list>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.format_sql">false</prop>
                <prop key="hibernate.generate_statistics">true</prop>
            </props>
        </property>
    </bean>

2# -

Pooling and connection info is in hibernate.cfg.xml

<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="configLocation" value="classpath:hibernate.cfg.xml" />
    </bean>

Source: (StackOverflow)

Whitelist security constraint in web.xml

I'm using Tomcat for my Struts2 application. The web.xml has certain entries as shown below:

<security-constraint>
    <web-resource-collection>
        <web-resource-name>restricted methods</web-resource-name>
        <url-pattern>/*</url-pattern>
        <http-method>PUT</http-method>
        <http-method>DELETE</http-method>
        <http-method>TRACE</http-method>
    </web-resource-collection>
    <auth-constraint />
</security-constraint>
<security-constraint>
   <web-resource-collection>
       <web-resource-name>no_access</web-resource-name>
       <url-pattern>/jsp/*</url-pattern>
   </web-resource-collection>
   <auth-constraint/>
</security-constraint>
    <security-constraint>
   <web-resource-collection>
       <web-resource-name>no_access</web-resource-name>
       <url-pattern>/myrrunner/*</url-pattern>
   </web-resource-collection>
   <auth-constraint/>
</security-constraint>

How can I change above blacklisted parts to use only whitelisting part... For example, instead of blacklisting PUT, DELTE http methods, I need to whitelist other methods but I'm not sure the syntax of whitelisting them & what methods to whitelist them.

For my above web.xml snippet, I'll appreciate if some one can provide me whitelisitng counter part for above xml.

EDIT: Also, how would I really verify whether the solution works or not?

Thanks


Source: (StackOverflow)