I have a confusion in understanding /implementing this page .
Hi , I am trying to follow this website for showing the Default Login page once the user logs in .
Please go through this to understand the question .
http://liferaydemystified.blogspot.in/2011/04/liferay-default-landing-page.html
I have some questions regarding this .
After entering this things inside the portal-ext.properties file
login.events.post=com.liferay.portal.events.LoginPostAction,
com..defaultlandingpage.CustomLandingPageAction
auth.forward.by.last.path=true
default.landing.page.path=
And i want to use the same CustomLandingPageAction as defined by the author in the web site .
The LoginMVCPortlet is my java file , which will recieve the parameters (Username and Password ) from the UI .
public class MyLoginPortlet extends MVCPortlet {
public void checkLogin(ActionRequest actionRequest,
ActionResponse actionResponse) throws IOException, PortletException {
String name = actionRequest.getParameter("name");
String password = actionRequest.getParameter("password");
// Contact the DB for validation .
}
My question is that , how this CustomLandingPageAction and my LoginMVCPortlet class are actually related .
Is this approach the correct one, or am I missing anything?
How to do this? I am using Liferay 6.1 for development.
Please let me know in case you need any information.
put redirection in portlet processAction methode:
#Override
public void processAction(ActionRequest actionRequest, ActionResponse actionResponse) throws IOException, PortletException {
//defaultLandingPage = ...
actionResponse.sendRedirect(defaultLandingPage);
};
Related
This is a controller of springboot, I want to write a function to redirect to an html page, but it always responded with 404, and here is the code and properties.
'
#Component
#Controller
#RequestMapping("/Weixin")
public class KindlePocketController {
private static final long serialVersionUID = 1L;
#Autowired
private TextBookInfoSearchService searchService;
#RequestMapping("/homepage")
public String toIndex() {
System.out.println("redirecting to homepage...");
return "index";
}
}
'
application.properties
'
spring.view.prefix=/WEB-INF/views/
spring.view.suffix=.html
'
the program can get into the function and output is ok. And index.html is in this path:/WEB-INF/views/index.html. Is there any else configurations ?
Thanks a lot
You got the incorrect configuration, try this:
spring.mvc.view.prefix=/WEB-INF/views/
spring.mvc.view.suffix=.html
Its spring.mvc.view.* and not spring.view.*.
PS: Use the Intelisense provided by STS or InteliJ.
This mapping #RequestMapping("/Weixin") maps to URL with that name:
Example: localhost:8080/Weixin
Second you have another mapping#RequestMapping("/homepage") which maps to URL:
Example2: localhost:8080/Weixin/homepage
You would be redirected to index page whenever you try to access that URL of Example2
We recently upgraded the application from Wicket 1.5.8 to 6.22.0. I am trying to set all pages to redirect to a specific page (SessionExpiredPage) when an action occurs after the session has expired.
public class WicketApplication<HttpsRequestCycleProcessor> extends WebApplication
{
// other methods omitted
public void init()
{
super.init();
getApplicationSettings().setPageExpiredErrorPage(SessionExpiredPage.class);
getApplicationSettings().setAccessDeniedPage(SessionExpiredPage.class);
getPageSettings().setRecreateMountedPagesAfterExpiry(false);
// several other mounted links omitted
mount(new MountedMapper("landingpage", LandingPage.class, new UrlPathPageParametersEncoder()));
// add your configuration here
getComponentInstantiationListeners().add(new SpringComponentInjector(this));
}
}
Setting setRecreateMountedPagesAfterExpiry to false helps redirect several pages upon session expiry, however there is an unintended consequence. The application contains several servlet pages. One of them is accessed from a wicket page like this:
#RequireHttps
public class SubscriptionPage extends WebPage
{
#Override
public void onSubmit()
{
String redirectUrl = null;
// condition checking code omitted
redirectUrl= "SubsCartTempServlet?subsunit=6";
// more code omitted
getRequestCycle().scheduleRequestHandlerAfterCurrent(new RedirectRequestHandler(redirectUrl));
}
}
The url is changed from http://localhost:8080/LatinParserK/SubsCartTempServlet?subsunit=6, which worked, to
http://localhost:8080/LatinParserK/wicket/SubsCartTempServlet?subsunit=6, which fails.
Can anyone explain how to work around this problem?
It seems the path to the Wicket page and to the Servlet have different depth.
Use org.apache.wicket.request.UrlUtils#rewriteToContextRelative(relativeUrl, cycle) to make the url to the Servlet relative to the context root.
The last line under onSubmit() was replaced with:
String relativeUrl = UrlUtils.rewriteToContextRelative(redirectUrl, getRequestCycle());
getRequestCycle().scheduleRequestHandlerAfterCurrent(new RedirectRequestHandler(relativeUrl));
That corrected the URL to the servlet.
How to authenticate and redirect a user to his own page i.e to www.mysite.com/"user's email".
I am using the following algo which is not working...
userDB in User class:
Map<String,String> userdata=new HashMap<String,String>();
First my login process form :
#Path("/login")
#POST
#Produces(MediaType.TEXT_HTML)
#Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public void login(
#FormParam("email") String emailc,
#FormParam("password") String pass,
#Context HttpServletResponse servletResponse
) throws IOException,RuntimeException {
User u1=new User();
pass=u1.getPassword();
emailc=u1.getEmailaddrs();
boolean checked=false;
boolean exists;
exists=u1.userdata.containsKey(emailc);
if(exists){
String mypass =u1.userdata.get(emailc);
if(mypass==pass){
checked=true;
}else{
checked=false;
}
}else{
checked=false;
}
if(!checked){
//User Doesn't exists
servletResponse.sendRedirect("http://localhost:8080/MySite/pages/Create_Profile.html");
}else{
servletResponse.sendRedirect("http://localhost:8080/MySite/{email}"); <<<< How to redirect using #FormParam("email")
}
}
createprofile
#POST
#Produces(MediaType.TEXT_HTML)
#Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public void newUser(
#FormParam("email") String email,
#FormParam("password") String password,
#Context HttpServletResponse servletResponse
) throws IOException {
User u = new User(email,password);
User.userdata.put(email,password);
}
Your usage of userdata [Map] looks wrong to me. Is it a part of user class, is it non static or static ?
If it is non static then every time you will do new User() .. that map will be initialized and it will have no data in it. Hence u1.userdata.containsKey(emailc); will be always false.
If you are using a hashmap as a temporary database for dev purposes then, make it static rather keep it in a different class like UserStore or some DB access layer. Exmaple below:
public class UserDAO(){
private static Map<String,User> userdata = new HashMap<String,User>();
public boolean hasUser(String email){
return userdata.contains(email);
}
public User saveUser(String email, String password ...){
//make user object save it in map and return the same
}
// more methods for delete and edit etc.
}
And use this in your REST layer classes like this
exists = userDao.hasUser(email);
Advantages :
Your problem will be solved.
Later on when you move to actual db implementation you will just have to change your UserDao code and rest application code will be just fine. -- Loose coupling :)
Also regarding forward using email
servletResponse.sendRedirect("http://localhost:8080/MySite/{email}"); <<<< How to redirect using #FormParam("email")
add the email parameter there in the url only, if thats what you want:
servletResponse.sendRedirect("http://localhost:8080/MySite/"+emailc);
UPDATE :
See the fundamental thing is that you get request parameters [email , password]. You check it whether it is present in map or not. Now what you are doing wrong here is you create a new user like this User u = new User(); and then get email and password from it emailc = u.getEmail();. This emailc will always be null and your userdata map will always return false for that. You have two choices :
Either set email and password in user object and then get the data from user object.
Use the email and password obtained from request parameters for your logic. Do not alter them
One good practice to follow while programming is that at all times think of your method parameters as final parameters.
UPDATE 2 :
if(mypass==pass){
checked=true;
}else{
checked=false;
}
Change == to equals method. String matching should be done by equals or equalsIgnoreCase method not ==.
You always create a new User without any parameters: User u1=new User();. All these User instances will have the same property values and probably exists is always false.
I read that the renderURL will be responsible to execute the renderPhase only (That is the doView Method of the java class )
Now in one of the JSP i have a Hyper Link to navigate to the another page as shown
(This is the starting page of the Portlet)
<a href="<portlet:renderURL>
<portlet:param name="goto" value="IpByHourPage"/>
<portlet:param name="jspPage" value="/page2.jsp" />
</portlet:renderURL>">
Click here to go to Second Page
</a>
Now my question is that , is it possible taht instead of getting the parameters inside the page2.jsp and processing it , is it possible that to recieve these parameters inside the java file that is
I want to recieve this parameters inside the SecondPort as shown below .
For example
public class SecondPort extends MVCPortlet {
public void doView(RenderRequest renderRequest, RenderResponse renderResponse throws IOException, PortletException
{
// do something in this code here .
}
Yes, you can get your parameter set in <portlet:param> tag in your portlet class.
You can read that parameter in doView method by following :-
public class SecondPort extends MVCPortlet {
public void doView(RenderRequest renderRequest, RenderResponse renderResponse throws
IOException, PortletException
{
String goto = renderRequest.getParameter("goto");
String jspPage= renderRequest.getParameter("jspPage");
//Do something here....
}
like this..
When I call other action in one action, it also display itself template, in Play 1.1 RC
and when I Redirect("...url") but it does not work, is there someone that can help me?
Just to add to the answers above, here's how you redirect to an external url:
public static void index() {
redirect("http://geeks.aretotally.in");
}
To redirect, you simply call the action. From the example in the documentation:
public static void show(Long id) {
Article article = Article.findById(id);
render(article);
}
public static void edit(Long id, String title) {
Article article = Article.findById(id);
article.title = title;
article.save();
show(id);
}
At the end of the edit action, the call to show(...) will cause a redirect on the client's browser as if they had hit the same URL that routes to the show method.
Since none of these answers provide a general/reusable method to do this, here is my code. This allows you to create any number of redirects in the conf/routes file without creating a controller for each.
Yes, this is trivial, but perhaps it is of use to someone.
conf/routes:
GET /admin Application.redirect(url:'/admin/index.html')
app/controllers/Application.java:
public class Application extends Controller {
public static void redirect(String url) {
redirect(url, true);
}
}
In the play framework, when you call an action, by default it renders the template associated with that action.
For example, a Contoller named Application
public static void index()
Will render
app/views/Application/index.html
To make it render a different view, then you can specify the template as the first parameter in the render method.
So,
renderTemplate("Application/myOtherTemplate.html");
Redirect should only really be used if you are redirecting to a URL outside of your application.