I am using Liferay6 with Struts2 .
This is the LOgin.jsp
<%# taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Struts 2 Login Application!</title>
</head>
<body>
<s:form action="login" method="POST" validate="true">
<tr>
<td colspan="2">
Login
</td>
</tr>
<s:actionerror />
<s:fielderror />
<s:textfield name="username" label="Login name"/>
<s:password name="password" label="Password"/>
<s:submit value="Login" align="center"/>
</s:form>
</body>
</html>
This is struts.xml file
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<package name="default" extends="struts-default" namespace="/view">
<action name="login"
class="net.LoginAction">
<result name="success">/Welcome.jsp</result>
<result name="error">/view.jsp</result>
</action>
</package>
</struts>
This is exception stacktrace
9:51:52,109 ERROR [Jsr168Dispatcher:27] Could not find action
There is no Action mapped for action name default. - [unknown location]
at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:177)
at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)
at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:47)
at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:36)
at org.apache.struts2.portlet.dispatcher.Jsr168Dispatcher.serviceAction(Jsr168Dispatcher.java:446)
at org.apache.struts2.portlet.dispatcher.Jsr168Dispatcher.render(Jsr168Dispatcher.java:323)
at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:100)
at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:64)
at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:93)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:72)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:68)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:593)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:530)
at com.liferay.portlet.InvokerPortletImpl.invoke(InvokerPortletImpl.java:639)
There is no Action mapped for action name default.
But your action name login
<action name="login" class="net.LoginAction">
Your actions url must be sitename/youapp/view/login.action
In addition for loggining your hava two actions.
<action name="prepareLogin" class="net.LoginAction" method="input">
<result name="success">/login.jsp</result>
</action>
prepareLogin - this action only view login page
<action name="login" class="net.LoginAction" method="execute">
<result name="success">/Welcome.jsp</result>
<result name="error">/login.jsp</result>
</action>
login - this action get loggining
Related
I am trying to run my struts application but I am getting a error action is not mapped I have seen the namespace it is correct but still getting the error?
struts.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="false" />
<include file="register.xml"/>
<!-- Add packages here -->
</struts>
And my register.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="register" namespace="/" extends="struts-default">
<action name="Register" class="com.struts2.RegisterAction">
<result name="input">/register.jsp</result>
<result type="redirectAction">register.jsp</result>
</action>
<!-- Add actions here -->
</package>
</struts>
I am validating my register page and the validation XML as follows
RegisterAction-validation.xml:
<!DOCTYPE validators PUBLIC
"-//OpenSymphony Group//XWork Validator 1.0.2//EN"
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
<validators>
<field name="username">
<field-validator type="requiredstring">
<message key="requiredstring"/>
</field-validator>
</field>
<field name="password">
<field-validator type="requiredstring">
<message key="requiredstring"/>
</field-validator>
<field-validator type="stringlength">
<param name="minLength">6</param>
<param name="trim">true</param>
<message key="requiredpassword"/>
</field-validator>
</field>
<field name="email">
<field-validator type="requiredstring">
<message key="requiredstring"/>
</field-validator>
<field-validator type="email">
<message key="requiredemail"/>
</field-validator>
</field>
<field name="gender">
<field-validator type="requiredstring">
<message key="requiredstring"/>
</field-validator>
</field>
<field name="postalcode">
<field-validator type="requiredstring">
<message key="requiredstring"/>
</field-validator>
<field-validator type="regex">
<param name="expression"><![CDATA[^\d*$]]></param>
<message key="requiredinteger"/>
</field-validator>
</field>
</validators>
And my register.jsp as follows:
<%# page contentType="text/html; charset=UTF-8" %>
<%# taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Validation Struts page</title>
<s:head/>
</head>
<body>
<s:form action="Register">
<s:textfield key="username"/>
<s:password key="password" />
<s:textfield key="email" />
<s:select headerKey="" headerValue="Select Gender"
key="gender" list="#{'M':'Male','F':'Female'}" />
<s:textfield key="postalcode" />
<s:submit/>
</s:form>
</body>
</html>
My Project Structure as Follows:
Strutsvalidation
--src-->
com.struts2(package)-->
register.xml,
registeraction-validation.xml,
javaclasses,
struts.xml
--webcontent-->
web-inf-->
web.xml
register.jsp(in web content)
I am getting the error as follows?
There is no Action mapped for action name Register. - [unknown location]
at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185)
at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:37)
at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:552)
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
This configuration is wrong
<result type="redirectAction">register.jsp</result>
use
<result>/register.jsp</result>
The redirectAction result should be used to redirect to the action, which name is used for location.
The exception comes from the s:form tag when you tried to submit it. The action Register actually packaged in namespace /. This not a default namespace and therefore should be used on the s:form tag.
<s:form namespace="/" action="Register">
It is possible to map multiple actions url in a single action configuration with wildcard ? I can able to do like */* */*/* in action names. But I don't know exactly how many nested path will come.
Since all my urls load render CommonLayout. So, I don't want to add multiple entries.
What I am doing now
<package name="myapp" extends="default" namespace="/">
<global-results>
<result type="tiles">CommonLayout</result>
</global-results>
<action name="a" />
<action name="a/create" />
<action name="b" />
<action name="b/customize" />
<action name="b/customize/app" />
<action name="d/create" />
<action name="d/view" />
<action name="d/view/list" />
</package>
Below is the configuration which I want to have, But It is not working for all nested actions.
<package name="myapp" extends="default" namespace="/">
<global-results>
<result type="tiles">CommonLayout</result>
</global-results>
<action name="*" />
</package>
here my development settings before I start with my problem:
Struts 2: 2.3.20.1
Tiles 2: 2.0.6
Struts2-DoJo-Plugin: 2.3.20.1
Struts2-JQuery-Plugin: 3.7.1
TomEE 7.0.55
Java 8: 1.8.0_25
IDE: IntelliJ 2016.2 Ultimate
Now my problem:
I want to use the DateTimePicker in Struts2-Dojo or *-JQuery, but for both API I get false paths in the generated HTML sides.
Look at these pictures what my results are:
Struts 2 - DOJO (1st Browser view, 2nd HTML src)
Struts 2 - JQuery (1st Browser view, 2nd HTML src)
You see my problem? The double dashes? Why did Struts that? Is that a problem with Tiles?
I need only one dash, I looked up on this community before on this link:
Relative Path in Struts 2 - DOJO
... and test this (you can see that under BaseLayout.jsp below) and it doesn't work for my problem.
Here my web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<display-name>Struts Tiles 2 Demo</display-name>
<context-param>
<param-name>tilesDefinitions</param-name>
<param-value>/WEB-INF/tiles.xml</param-value>
</context-param>
<listener>
<listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
</listener>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
The struts.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="false"/>
<constant name="struts.devMode" value="false"/>
<!--suppress InjectedReferences -->
<package name="default" extends="struts-default" namespace="/">
<result-types>
<result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult"/>
</result-types>
<default-action-ref name="start"/>
<action name="start">
<result name="success" type="tiles">index</result>
<result name="error" type="tiles">err404</result>
</action>
<action name="err404">
<result name="success" type="tiles">err404</result>
</action>
<action name="dbTest">
<result name="success" type="tiles">dbTest</result>
<result name="error" type="tiles">err404</result>
</action>
<action name="dtpJQ">
<result name="success" type="tiles">dtpJQ</result>
<result name="error" type="tiles">err404</result>
</action>
</package>
</struts>
The tiles.xml:
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
"http://tiles.apache.org/dtds/tiles-config_2_0.dtd">
<tiles-definitions>
<definition name="baseLayout" template="/WEB-INF/tiles/layouts/BaseLayout.jsp">
<put-attribute name="title" value="" />
<put-attribute name="header" value="/WEB-INF/tiles/parts/Header.jsp" />
<put-attribute name="menu" value="/WEB-INF/tiles/parts/Menu.jsp" />
<put-attribute name="body" value="" />
<put-attribute name="footer" value="/WEB-INF/tiles/parts/Footer.jsp" />
<!-- only true or false -->
<put-attribute name="isDojoActive" value="false" />
<put-attribute name="isJQueryActive" value="false" />
</definition>
<definition name="index" extends="baseLayout">
<put-attribute name="title" value=".: 1st Steps Base Layout Struts 2 :." />
<put-attribute name="body" value="/WEB-INF/tiles/body/start.jsp" />
</definition>
<definition name="err404" extends="baseLayout">
<put-attribute name="title" value=".: Test Error 404 Page :." />
<put-attribute name="body" value="/WEB-INF/tiles/errorPages/404.jsp" />
</definition>
<definition name="dbTest" extends="baseLayout">
<put-attribute name="title" value=".: DB Test :." />
<put-attribute name="body" value="/WEB-INF/tiles/tableViews/dbTest.jsp" />
</definition>
<definition name="dtpTest" extends="baseLayout">
<put-attribute name="title" value=".: Date Time Picker Test - START :." />
<put-attribute name="body" value="/WEB-INF/tiles/body/testDTP.jsp" />
<put-attribute name="isDojoActive" value="true" />
</definition>
<definition name="dtpJQ" extends="baseLayout">
<put-attribute name="title" value=".: DTP JQ TEST :." />
<put-attribute name="body" value="/WEB-INF/tiles/modules/dateTimePickerJQuery.jsp" />
<put-attribute name="isJQueryActive" value="true" />
</definition>
<definition name="dateTimePicker" extends="baseLayout">
<put-attribute name="title" value=".: Date Time Picker Test :." />
<put-attribute name="body" value="/WEB-INF/tiles/modules/dateTimePicker.jsp" />
</definition>
</tiles-definitions>
BaseLayout.jsp:
<%#page contentType="text/html;charset=UTF-8" language="java" %>
<%#taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>
<%#taglib prefix="s" uri="/struts-tags" %>
<%#taglib prefix="sx" uri="/struts-dojo-tags" %>
<%#taglib prefix="sj" uri="/struts-jquery-tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title><tiles:insertAttribute name="title" ignore="true" /></title>
<style type="text/css">#import url(/css/main.css);</style>
<s:set var="isDojoActive"><tiles:getAsString name="isDojoActive" /></s:set>
<s:set var="isJQueryActive"><tiles:getAsString name="isJQueryActive" /></s:set>
<s:if test='%{#isDojoActive.equals("true")}'>
<sx:head baseRelativePath="/struts/dojo" debug="true" parseContent="false" />
</s:if>
<s:if test='%{#isJQueryActive.equals("true")}'>
<sj:head />
</s:if>
</head>
<body>
<div class="container">
<div id="baseLeft"><tiles:insertAttribute name="menu" /></div>
<div id="baseRight">
<div class="inner-content header center"><tiles:insertAttribute name="header" /></div>
<div class="inner-content body"><tiles:insertAttribute name="body" /></div>
<div class="inner-content footer right"><tiles:insertAttribute name="footer" /></div>
</div>
</div>
</body>
</html>
I found the mistake:
My TomEE configuration under IntelliJ IDEA:
The missing root/application context.
I am trying to change default url in my application using below code,
struts.xml :
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name="struts.action.extension" value="htm"/>
<package name="default" namespace="/" extends="struts-default" >
<action name="LoginClass" class="com.struts2.LoginCheckingClass" method="execute">
<result name="input">/Home.jsp</result>
<result name="success" type="dispatcher">/LoginSuccessPage.jsp</result>
<result name="error">/Home.jsp</result>
</action>
</package>
</struts>
Home.jsp :
<s:actionerror/><s:fielderror />
<br>
<s:form action="LoginClass" method="post" validate="true">
<s:textfield name="Uname" label="User Name" />
<s:textfield name="Pwd" label="Password" />
<s:submit validate="true" type="image" src="button-login2.png"/>
</s:form>
But when submit in Home.jsp the page always goes to 404 error page.I saw all tutorials and doing that same way but still i am getting same error.
If i remove the <constant name="struts.action.extension" value="htm"/> from struts.xml then page redirecting to represented page correctly.
someone help me out where am i doing wrong?
I am a beginner to struts2. i am using struts2 token interceptor to prevent CSRF. the token interceptor in working for the login page, but it is not working for the second page. the second page is just a JSP with hyperlinks, and when i change the token value it says "Could not find token name in params" . this is my code
Jsp
<div style="margin: 0 auto; font-size: 16px;">
<s:token />
<a href="<s:url value="view" />" >Click Here to View and Search Data</a>
<br/><br/>
<a href="<s:url value="Upload.jsp" />" >Click here to Upload Data (CSV format)</a>
<br/><br/>
<a href="<s:url value="Register.jsp" />" >Click here to Upload Data (FORM)</a>
</div>
Struts.xml
<package name="default" extends="struts-default, json-default">
<!-- CREATING INTERCEPTOR -->
<interceptors>
<interceptor-stack name="myStack">
<interceptor-ref name="defaultStack" />
<interceptor-ref name="tokenSession" />
<interceptor-ref name="timer"/>
<interceptor-ref name="logger"/>
<interceptor-ref name="fileUpload" />
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="myStack"/>
<global-results>
<result name="invalid.token">/error.jsp</result>
</global-results>
<action name="login" class="action.loginAction">
<result name="input">/Login.jsp</result>
<result name="success">/Main.jsp</result>
<result name="error">/error.jsp</result>
</action>
how do i implement token intercepto for this jsp.
please suggest
Try changing order of interceptors , keep defaultStack in last.
<interceptors>
<interceptor-stack name="myStack">
<interceptor-ref name="tokenSession" />
<interceptor-ref name="timer"/>
<interceptor-ref name="logger"/>
<interceptor-ref name="fileUpload" />
<interceptor-ref name="defaultStack" />
</interceptor-stack>
</interceptors>
Try using token instead of tokenSession.
<interceptor-ref name="token" />
Also post the struts mapping for second page submit.