sangeetha
asked on
Struts - Validate, forward and re-direct.
W.r.to:
https://www.experts-exchange.com/questions/21097832/Struts-Forward-page-Problem.html
1. How can i make sure that if i set redirect=true,
how can i write an interim stage to save the errors into the session instead of the request, and then write a listener to extract them back out again.
2. Can i use include="blah..blah" in my <action ..> of my struts-config.xml ?
Thanks.
https://www.experts-exchange.com/questions/21097832/Struts-Forward-page-Problem.html
1. How can i make sure that if i set redirect=true,
how can i write an interim stage to save the errors into the session instead of the request, and then write a listener to extract them back out again.
2. Can i use include="blah..blah" in my <action ..> of my struts-config.xml ?
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yes..Validation errors.
:-)
:-)
ASKER
I am getting "sess" cannot be resolved.
Do i need to create a local variable like:
ServletRequest sess = null;
Do i need to create a local variable like:
ServletRequest sess = null;
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
whoops sorry...
ASKER
I am getting:
The method getSession() is undefined for the type ServletRequest
:-(
The method getSession() is undefined for the type ServletRequest
:-(
You have to return an HttpSession object. Look at my comment above.
ASKER
Yes...I included that and got that error. This is what i have now:
public class MyFilter implements Filter {
/* (non-Javadoc)
* @see javax.servlet.Filter#doFil ter(javax. servlet.Se rvletReque st, javax.servlet.ServletRespo nse, javax.servlet.FilterChain)
*/
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
HttpSession sess = request.getSession();
Object err = sess.getAttribute( org.apache.struts.Globals. ERROR_KEY );
sess.removeAttribute( org.apache.struts.Globals. ERROR_KEY );
if( err != null ) {
request.setAttribute( org.apache.struts.Globals. ERROR_KEY, err ) ;
chain.doFilter( request, response ) ;
}
}
/* (non-Javadoc)
* @see javax.servlet.Filter#init( javax.serv let.Filter Config)
*/
public void init(FilterConfig arg0) throws ServletException {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see javax.servlet.Filter#destr oy()
*/
public void destroy() {
// TODO Auto-generated method stub
}
}
but i get the above error.
public class MyFilter implements Filter {
/* (non-Javadoc)
* @see javax.servlet.Filter#doFil
*/
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
HttpSession sess = request.getSession();
Object err = sess.getAttribute( org.apache.struts.Globals.
sess.removeAttribute( org.apache.struts.Globals.
if( err != null ) {
request.setAttribute( org.apache.struts.Globals.
chain.doFilter( request, response ) ;
}
}
/* (non-Javadoc)
* @see javax.servlet.Filter#init(
*/
public void init(FilterConfig arg0) throws ServletException {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see javax.servlet.Filter#destr
*/
public void destroy() {
// TODO Auto-generated method stub
}
}
but i get the above error.
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
HttpSession sess = ((HttpServletRequest)reque st).getSes sion();
Object err = sess.getAttribute( org.apache.struts.Globals. ERROR_KEY );
sess.removeAttribute( org.apache.struts.Globals. ERROR_KEY );
if( err != null ) {
request.setAttribute( org.apache.struts.Globals. ERROR_KEY, err ) ;
chain.doFilter( request, response ) ;
}
}
FilterChain chain) throws IOException, ServletException {
HttpSession sess = ((HttpServletRequest)reque
Object err = sess.getAttribute( org.apache.struts.Globals.
sess.removeAttribute( org.apache.struts.Globals.
if( err != null ) {
request.setAttribute( org.apache.struts.Globals.
chain.doFilter( request, response ) ;
}
}
Can you try this:
HttpSession sess = ((HttpServletRequest) request).getSession();
HttpSession sess = ((HttpServletRequest) request).getSession();
Or just change the parameter to be of type HttpServletRequest/Respons e
ASKER
Ok..thanks....
now, where should i put:
<filter>
<filter-name>requestfilter </filter-n ame>
<filter-class>my.package.M yFilter</f ilter-clas s>
</filter>
in my web.xml file. I am getting errors if i put anywhere in the file. This is my web.xml :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>action</serv let-name>
<servlet-class>org.apache. struts.act ion.Action Servlet</s ervlet-cla ss>
<init-param>
<param-name>config</param- name>
<param-value>/WEB-INF/stru ts-config. xml</param -value>
</init-param>
<init-param>
<param-name>debug</param-n ame>
<param-value>3</param-valu e>
</init-param>
<init-param>
<param-name>detail</param- name>
<param-value>3</param-valu e>
</init-param>
<load-on-startup>0</load-o n-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</serv let-name>
<url-pattern>*.do</url-pat tern>
</servlet-mapping>
</web-app>
now, where should i put:
<filter>
<filter-name>requestfilter
<filter-class>my.package.M
</filter>
in my web.xml file. I am getting errors if i put anywhere in the file. This is my web.xml :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>action</serv
<servlet-class>org.apache.
<init-param>
<param-name>config</param-
<param-value>/WEB-INF/stru
</init-param>
<init-param>
<param-name>debug</param-n
<param-value>3</param-valu
</init-param>
<init-param>
<param-name>detail</param-
<param-value>3</param-valu
</init-param>
<load-on-startup>0</load-o
</servlet>
<servlet-mapping>
<servlet-name>action</serv
<url-pattern>*.do</url-pat
</servlet-mapping>
</web-app>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok...didnt show any error in the file. but i am getting the following error in my 'Console':
15:05:38,660 INFO [TomcatDeployer] undeploy, ctxPath=/KalendarTool, warUrl=file:/C:/Programme/ jboss/serv er/default /deploy/Ka lendarTool .war/
15:05:38,785 INFO [TomcatDeployer] deploy, ctxPath=/KalendarTool, warUrl=file:/C:/Programme/ jboss/serv er/default /deploy/Ka lendarTool .war/
15:05:39,129 INFO [PropertyMessageResources] Initializing, config='org.apache.struts. action.Act ionResourc es', returnNull=true
15:05:39,175 ERROR [Digester] Begin event threw exception
java.lang.reflect.Invocati onTargetEx ception
// blah..blah..
Caused by: java.lang.LinkageError: loader constraints violated when linking org/apache/struts/action/A ctionMappi ng class
at java.lang.Class.forName0(N ative Method)
at java.lang.Class.forName(Cl ass.java:1 41)
at org.apache.struts.config.F ormBeanCon fig.class$ (FormBeanC onfig.java :190)
at org.apache.struts.config.F ormBeanCon fig.setTyp e(FormBean Config.jav a:190)
... 97 more
15:05:39,191 ERROR [ActionServlet] Parsing error processing resource path
java.lang.reflect.Invocati onTargetEx ception
// blah..blah..
Thanks for your responses. I will award points. Meanwhile, Please tell me how can i resolve this.
15:05:38,660 INFO [TomcatDeployer] undeploy, ctxPath=/KalendarTool, warUrl=file:/C:/Programme/
15:05:38,785 INFO [TomcatDeployer] deploy, ctxPath=/KalendarTool, warUrl=file:/C:/Programme/
15:05:39,129 INFO [PropertyMessageResources]
15:05:39,175 ERROR [Digester] Begin event threw exception
java.lang.reflect.Invocati
// blah..blah..
Caused by: java.lang.LinkageError: loader constraints violated when linking org/apache/struts/action/A
at java.lang.Class.forName0(N
at java.lang.Class.forName(Cl
at org.apache.struts.config.F
at org.apache.struts.config.F
... 97 more
15:05:39,191 ERROR [ActionServlet] Parsing error processing resource path
java.lang.reflect.Invocati
// blah..blah..
Thanks for your responses. I will award points. Meanwhile, Please tell me how can i resolve this.
ASKER
My web.xml is as follows:
<web-app>
<filter>
<filter-name> requestfilter </filter-name>
<filter-class>de.grassgmbh .kalendart ool.filter s.MyFilter </filter-c lass>
</filter>
<servlet>
// blah...blah..
<web-app>
<filter>
<filter-name> requestfilter </filter-name>
<filter-class>de.grassgmbh
</filter>
<servlet>
// blah...blah..
There is a parsing error somewhere. Does it happen when you try to forward or call a JSP page? Can you post your forward code?
ASKER
The error is shown when i save the web.xml file !
Is it problem in detecting the MyFilter Package?
I have:
KalendarTool
|
|____ src
| |
| |___ de.grassgmbh.kalendartool
| | |
| | |____ resources.properties
| |
| |___ de.grassgmbh.kalendartool. form
| | |
| | |___ FilterForm.java
| | |___ RegisterMaskForm.java
| |
| |___ de.grassgmbh.kalendartool. action
| | |
| | |___ FilterAction.java
| | |___ RegisterMaskAction.java
| |
| |___ de.grassgmbh.kalendartool. filters
| |
| |___ MyFilter.java
|
|_____ We-Root
|
|____ WEB-INF
| |
| |____ struts-config.xml, web.xml, etc..
|
|____ jsp
|
|____ MynageCapacity
| |
|____ FilterList.jsp
|____ RegisterMaskList.jsp
|____ ShowList.jsp
Is it problem in detecting the MyFilter Package?
I have:
KalendarTool
|
|____ src
| |
| |___ de.grassgmbh.kalendartool
| | |
| | |____ resources.properties
| |
| |___ de.grassgmbh.kalendartool.
| | |
| | |___ FilterForm.java
| | |___ RegisterMaskForm.java
| |
| |___ de.grassgmbh.kalendartool.
| | |
| | |___ FilterAction.java
| | |___ RegisterMaskAction.java
| |
| |___ de.grassgmbh.kalendartool.
| |
| |___ MyFilter.java
|
|_____ We-Root
|
|____ WEB-INF
| |
| |____ struts-config.xml, web.xml, etc..
|
|____ jsp
|
|____ MynageCapacity
| |
|____ FilterList.jsp
|____ RegisterMaskList.jsp
|____ ShowList.jsp
ASKER
BTW,
<filter-class>de.grassgmbh .kalendart ool.filter s.MyFilter </filter-c lass> refers to the Filter Class.
but why and where we use: <filter-name> requestfilter </filter-name>
?
Thanks.
<filter-class>de.grassgmbh
but why and where we use: <filter-name> requestfilter </filter-name>
?
Thanks.
Can you post the xml file?
> <filter-name> requestfilter </filter-name>
The <filter-name> tag defines the logical name of the filter that you use to access it. It can be different than the actual filter class.
> <filter-name> requestfilter </filter-name>
The <filter-name> tag defines the logical name of the filter that you use to access it. It can be different than the actual filter class.
ASKER
Thanks again. :-)
I posted here:
https://www.experts-exchange.com/questions/21098119/To-girinois-TimYates.html
I posted here:
https://www.experts-exchange.com/questions/21098119/To-girinois-TimYates.html
2. No AFAIK.