Apache Struts: Cannot retrieve ActionForward - apache

I am trying to learn the Apache Struts framework and I have written a small application that does class enrollments but whenever I try and load up my application it just spits out the following exception:
javax.servlet.ServletException:
org.apache.jasper.JasperException:
javax.servlet.ServletException:
javax.servlet.jsp.JspException: Cannot create rewrite URL:
java.net.MalformedURLException: Cannot retrieve ActionForward named adminLogin
My index.jsp page looks like:
<%# taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<logic:redirect forward="showLogin"/>
The relevant parts of my struts-config.xml:
<global-forwards>
<forward name="showLogin" path="/showLogin.do" />
</global-forwards>
<action-mappings>
<action path="/showLogin" forward="/pages/choose.jsp" />
<action path="/adminLogin" forward="/pages/adminLogin.jsp" />
</action-mappings>
And finally the choose.jsp file:
<%# page import="javax.sql.*"%>
<%# taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%# taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<h1>Who are you?</h1>
<ul>
<li><html:link forward="adminLogin">Administrator</html:link></li>
<li><html:link forward="instructorLogin">Instructor</html:link></li>
<li><html:link forward="studentLogin">Student</html:link></li>
</ul>

I don't do Struts, so don't pin me on it, but the error seems to indicate that it is expecting a <forward name="adminLogin" /> somewhere in the config. You might want to have the same for the other two forwards.

Related

Sitecore 8.2 ItemService api working in main website but not in microsites

I have a website that has a primary home node as well as several microsites (each of which is a different language), configured like so:
<sites>
<site name="website-swedish" itemwebapi.mode="StandardSecurity" itemwebapi.access="ReadOnly" itemwebapi.allowanonymousaccess="true" patch:source="x.Sites.config" enableTracking="true" virtualFolder="/" physicalFolder="/" rootPath="/sitecore/content" startItem="/Swedish" hostName="se.mysite.com" language="sv" database="web" domain="extranet" allowDebug="true" cacheHtml="true" htmlCacheSize="50MB" registryCacheSize="0" viewStateCacheSize="0" xslCacheSize="25MB" filteredItemsCacheSize="10MB" enablePreview="true" enableWebEdit="true" enableDebugger="true" disableClientData="false" cacheRenderingParameters="true" renderingParametersCacheSize="10MB"/>
<site name="website" enableTracking="true" virtualFolder="/" physicalFolder="/" rootPath="/sitecore/content" startItem="/home" domain="extranet" allowDebug="true" cacheHtml="true" htmlCacheSize="50MB" registryCacheSize="0" viewStateCacheSize="0" xslCacheSize="25MB" filteredItemsCacheSize="10MB" enablePreview="true" enableWebEdit="true" enableDebugger="true" disableClientData="false" cacheRenderingParameters="true" renderingParametersCacheSize="10MB" language="en" patch:source="x.Sites.config" formsRoot="{F1F7AAB6-C8CE-422F-A214-F610C109FA63}" enableItemLanguageFallback="false" enableFieldLanguageFallback="false" itemwebapi.mode="StandardSecurity" itemwebapi.access="ReadOnly" itemwebapi.allowanonymousaccess="true" database="web"/>
</sites>
InSitecore.Services.Client.config I changed SecurityPolicy to ServicesOnPolicy:
<setting name="Sitecore.Services.SecurityPolicy" value="Sitecore.Services.Infrastructure.Web.Http.Security.ServicesOnPolicy, Sitecore.Services.Infrastructure" />
When I make a call to the ItemService on my main website, such as mysite.com/sitecore/api/ssc/item/0CF2CD64-2A60-47AE-A2F2-7FD1B599EE04, it works as expected. However, when I make a call on the microsite, e.g. se.mysite.com/sitecore/api/ssc/item/0CF2CD64-2A60-47AE-A2F2-7FD1B599EE04, I get a 403 error.
In addition to the SecurityPolicy setting I also had to change the AllowAnonymousUser setting to true:
<setting name="Sitecore.Services.AllowAnonymousUser" value="true" />

MVC CustomError not found

I'm trying to debug in VS express 2013 with my MVC4 application.
In a view, I've added a nonsense link, such as link, but I don't see the intended View when I click on the link, I see the IIS page.
I did this by creating an ErrorController which is
public class ErrorController : Controller
{
public ActionResult Index()
{
return View();
}
}
My view remains as the default, I didn't update it.
And my webconfig is
<customErrors mode="On" defaultRedirect="~/Error">
</customErrors>
The routes are the default!
The IIS message is
HTTP Error 404.0 - Not Found
If I type in http://localhost:53258/error/ then I see the page, suggesting that the mapping is fine.
What have I done wrong?
Check for this in your web.config, and add it if you don't have it:
<httpErrors errorMode="Custom" existingResponse="PassThrough" />
Try updating your customErrors node to add this:
<error statusCode="404" redirect="~/Error" />
Thus, your custom errors section would look like:
<customErrors mode="On">
<error statusCode="404" redirect="~/Error" />
</customErrors>

cannot retrieve mapping for action error

im using struts 1.2 and trying to create a link in jsp page with code
<html:link href="AdminModule/UserCreation.jsp" >
Create User </html:link> `
so that the link will move to page UserCreation in which the code like this is present
<html:form action="/adminUserCreation">
AdminName : <html:text property="username"/><html:errors property="username"/><br/>
Password : <html:password property="password"/><html:errors property="password"/><br/>
<html:submit/>
</html:form>
the struts-config file contain code like this
<form-beans>
<form-bean name="adminUserCreationForm" type="Admin.Form.AdminUserCreationForm" />
</form-beans>
<action-mappings>
<action
attribute="adminUserCreationForm"
input="/AdminModule/AdminHomePage.jsp"
name="adminUserCreationForm"
path="/adminUserCreation"
scope="request"
type="Admin.Action.AdminUserCreationAction"
validate="false">
<set-property property="cancellable" value="true" />
<forward name="failure" path="/AdminModule/AdminErrorPage.jsp" />
<forward name="success" path="/AdminSuccessPage.jsp" />
</action>
</action-mappings>
im getng exception
An exception occurred processing JSP page /AdminModule/UserCreation.jsp at line 30
30: <html:form action="/adminUserCreation">
31: AdminName : <html:text property="username"/><html:errors property="username"/><br/>
32: Password : <html:password property="password"/><html:errors property="password"/><br/>
33: <html:submit/>
root cause is
javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot retrieve mapping for action /adminUserCreation
How to open one jsp from another through struts
This helped me to solve it..
Maybe it will be helpful for anyone else who has the same problem.

Add Custom Webparts to Custom ASPX Page in SharePoint 2010

I am creating a custom aspx page to deploy to my SharePoint 2010 site.
Is it possible to have regions in my custom aspx page to allocate webparts to?
I am planning on creating some custom webparts and being able to move them around the page if needed would be a benefit for my aspx page.
Thanks.
Yes, use the standard WebPartZones with the sharepoint master pages (so you can add/configure the webparts)
<%# Page language="C#" MasterPageFile="~masterurl/default.master" Inherits="Microsoft.SharePoint.WebPartPages.WebPartPage,Microsoft.SharePoint,Version=14.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" %>
<%# Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%# Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%# Import Namespace="Microsoft.SharePoint" %>
<%# Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%# Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">
<WebPartPages:WebPartZone runat="server" FrameType="None" ID="Main" Title="loc:Main"></WebPartPages:WebPartZone>
</asp:Content>
If you dont have the sharepoint master page, or any master page, you could still have the zones, but it is going to be hard work setting up the webpart editing tools.

How do you get a Struts2 value from the .properties file programatically?

Say I have a struts.properties file with a defined value uploads.directory . How can I access that value from an Actioncontext programatically?
You can use getText("some.property.name") which return you the property value
http://struts.apache.org/maven/struts2-core/apidocs/com/opensymphony/xwork2/ActionSupport.html
Create ActionSupport Object and by using getText() method of ActionSupport class.
ActionSupport actionSupport = new ActionSupport();
actionSupport.getText("foo.bar");
Create a resources folder under src.
In the struts.xml file add a constant e.g., <constant name="struts.custom.i18n.resources" value="global"></constant>
Here global is the name of properties file.
Now you will be able to use the properties in the entire application.
<?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 to define result path locations to project root directory -->
<!-- constant to define global resource bundle -->
<constant name="struts.custom.i18n.resources" value="global"></constant>
<package name="user" namespace="/" extends="struts-default">
<action name="home">
<result>/home.jsp</result>
</action>
<action name="welcome" class="com.waqar.struts2.actions.WelcomeAction">
<result name="success">/welcome.jsp</result>
</action>
</package>
</struts>
The welcome.jsp
<%# page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%# taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><s:property value="getText('action.welcome.title')"/></title>
</head>
<body>
<s:property value="getText('action.welcome.username')"/>: <s:property value="username"/><br>
</body>
</html>
global.properties
action.welcome.username=waqar
In action class
System.out.println(getText("action.welcome.username"));
You need to put the my.properties file or my_locale.propeties file in the package that houses your action class.
You need to put the values in properties files other than struts.properties for examples ApplicationResources.properties or my.properties which needs to be in the classpath. struts.properties file is used to load struts specific properties for example struts.i18n.encoding=UTF-8 or struts.devMode = false etc.
The thing you need to do in struts.properties after you create the properties file for your customized messages is you have to add the following property in struts.properties file
struts.custom.i18n.resources=ApplicationResources
If you have more than one custom message property files then you need to add them by separating with comma for example:
struts.custom.i18n.resources=ApplicationResources,my
Then in your action classes you can access the property values by using getText('propertyName')
you can get value from message resource file like this:
public class MyAction extends ActionSupport {
public String getUserDetails() {
if("First Name".equals(getText("label.firstName"))) {
System.out.println("In if block");
}
}
}
you can also get more information, how to get values from .properties files in java class or jsp files.
for JSP:
<s:text name="label.firstName" />
and
<s:property value="getText('label.age')" />
for more information you can go through this link:
get info here