w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Redirect to an external URL from controller action in Spring MVC
For external url you have to use "http://www.yahoo.com" as the redirect url. This is explained in the redirect: prefix of Spring reference documentation. redirect:/myapp/some/resource will redirect relative to the current Servlet context, while a name such as redirect:http://myhost.com/some/arbitrary/path will redirect to an absolute URL

Categories : Java

How to Handle Redirect Flow in Spring Controller
In this situation follow Post/Redirect/Get pattern flow. When server side validation fails (result.hasErrors()) do not redirect but display index page again. Spring handles passing errors to template. To display errors use function of your template engine that supports Spring MVC (for example display all errors in JSP - <form:errors path="*" element="div" />). @Controller public class MyController { @RequestMapping(value="/index.html", method=RequestMethod.GET) public String display(@ModelAttribute MyForm myForm){ return "index"; } @RequestMapping(value="/process.do", method=RequestMethod.POST) public String processForm(@ModelAttribute @Validated MyForm myForm, BindingResult result) { if(result.hasErrors()){

Categories : Spring

Overriding an abstract method means class abstract class or not in java?
If you extend A and implement the abstract method (as you have done), B does not have to be abstract. On a related note, if you only have one abstract method and no concrete methods, you could declare your abstract class instead as an interface like so: interface class A { void area(); } class B implements A { void area(){ System.out.print("area by class B"); } }

Categories : Java

How to get a HTML submit button in an ASP.NET page to call a controller method in MVC controller class
In your tag, give the URL to your controller/action to action attribute and put your HTML in your form. <form action='@Url.Action("LogIn","ControllerName")' method="post" > <h1>Login</h1> Username <br /> <input id="Text1" type="text" /><br /> <br /> Password <br /> <input id="Password1" type="password" /><br /> <br /> <input id="Submit1" type="submit" value="Login" /><br /> </div> </form>

Categories : Asp Net Mvc

Spring Security need to redirect to Login Page on BadCredentialsException
Take a look here: http://www.codemarvels.com/2010/12/spring-security-3-how-to-display-login-errors/ To sum up, it says that you should capture in a controller the different mappings used in authenticationFailureHandler. Then you can redirect to any jsp and use the messages you need.

Categories : Spring

When your controller action respond with json, how to get action_name.js.erb to redirect to another page?
You can do it in controller as well class OrdersController < ApplicationController def perform_review ... @order = get_order respond_to do |format| format.html { redirect_to orders_path(current_user) } format.js {render :js => "window.location.href = '"+orders_path(current_user)+"'"} if @order.blank? end end end In this way you do not need the if else in your perform_review.js.erb. And if you want to do in the view file, then here is the following code. <% if (@order.blank?) %> window.location.href = "<%= escape_javascript(@redirect_path) %>"; <% else %> // your code <% end %>

Categories : Ruby On Rails

php abstract class inheritance error with no abstract method to inherit
You are saying it is implementing an interface. Between all of the inheriting classes must implement all of the interface methods So for example your AbstractViewDecorator could implement 2 of the methods, and OuterViewDecorator could implement the last 4, or OuterViewDecorator could do all 6.. As long as all of the methods are implements in the class inheritance chain.

Categories : PHP

Play Framework - how do I redirect to a page generated by a plugin controller? [SecureSocial]
In order to show the message, you must have an item in the Flash. When you hit /login directly, there is no flash, so you won't see that message. If you want to see that message: Redirect(securesocial.controllers.LoginPage.login).flashing( ... )

Categories : Http

Extending an abstract class - implementing abstract methods
You have to provide an implementation to all abstract methods. Even if no part of the program calls them now a class can be created in the future that does call them, or the super class implementation may be changed. A stub is needed even if it's just for binary compatibility.

Categories : Java

'Cannot instantiate abstract class' although class shouldn't be abstract
You need to define the ~FirstClass() destructor and leave out its constructor class FirstClass { public: virtual ~FirstClass(void) {} // or use C++11 = default syntax virtual void Foo() = 0; virtual void Bar() = 0; }; class SecondClass : public FirstClass { public: SecondClass(); virtual ~SecondClass(void); void Foo(); void Bar(); }; SecondClass::SecondClass() {} SecondClass::~SecondClass(void) {} void SecondClass::Foo() {} void SecondClass::Bar() {} int main() { SecondClass mSecClass; } Live Example.

Categories : C++

want to close popup and redirect to respective page without any event just after executing the PHP script on controller
Call this JS in popup page: window.opener.location.href = "http://some/new/location"; window.close(); PHP Code echo"<script language='javascript'>"; echo("window.opener.location.href = '" . $strRedirectUrl . "';"); echo("window.close();"); echo "</script>"; Demo : Page 1 file : page_1.php <!DOCTYPE html> <html> <head> <script type="text/javascript"> // Popup window code function newPopup(url) { popupWindow = window.open( url,'popUpWindow','height=700,width=800,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes') } </script> </head> <body> <a href="JavaScript:newPopup('page_2.php');">Open a popup window</a> </body> </html> Page 2: file

Categories : PHP

When to use HttpServletRequest class in a Spring Mvc Controller
Use it whenever you need to use it... In this example, the author is using it get the character encoding : return "redirect:/contacts/" + UrlUtil.encodeUrlPathSegment(contact.getId().toString(), httpServletRequest); Here is the code from the UrlUtil class : public class UrlUtil { public static String encodeUrlPathSegment(String pathSegment, HttpServletRequest httpServletRequest) { String enc = httpServletRequest.getCharacterEncoding(); if (enc == null) { enc = WebUtils.DEFAULT_CHARACTER_ENCODING; } try { pathSegment = UriUtils.encodePathSegment(pathSegment, enc); } catch (UnsupportedEncodingException uee) { } return pathSegment; } } More information about the HttpServletRequest class

Categories : Spring

passing an object from view page to Spring controller
You seem to want to use Thymeleaf's selector expression with th:object="${refreshFacetsRequest}". The notation for that is *{someField}. Change your elements accordingly <input type="hidden" id="category" name="category" th:if="*{category}" th:value="*{category}"/> The above would resolve to ${refreshFacetsRequest.category}. EDIT Going from View to Controller, what you're doing is making your browser send an HTTP request to an HTTP server (your servlet container). There is no notion of objects here. The <input> field with name category will be passed as a request parameter in the HTTP POST. Spring is usually smart enough to transform from request parameters to objects, but it needs some information. Is Category an enum? If it is, Spring will attempt to use Category.value

Categories : Javascript

Download secure page from controller, Spring security
Solved my own question! I was able to get this to work by passing the JSESSIONID as a cookie in my request. So going from my code in my question, it would look like this: @Controller @RequestMapping("/secure") public class SecureArea { @RequestMapping("/downloadMe.xhtml") public String downloadMe(HttpServletRequest request, HttpServletResponse response) throws Exception { // do stuff return "myJsp"; } @RequestMapping("/viewStuff") public void viewStuff(HttpServletRequest request, HttpServletResponse response) throws Exception { URL url = new URL("http://"+request.getServerName()+":"+request.getServerPort()+"/secure/downloadMe.xhtml"); URLConnection con = url.openConnection(); con.setDoOutput(true); // attach the session

Categories : Java

How to get checked checkbox value from html page to spring mvc controller
I have used JSTL with JSP and thymeleaf was something new. I read the THYMELEAF documentation. There is a section which explains multi valued check boxes. <input type="checkbox" class="ads_Checkbox" th:text="${q.questionName}" th:value="${q.id}" name="id"/> In the above code we are not binding the value to the field of the command object. Instead try doing this <input type="checkbox" class="ads_Checkbox" th:text="${q.questionName}" th:field="*{selectedQuestions}" th:value="${q.id}" /> here the selectedQuestions is an array object present in the spring command object.

Categories : Spring

Abstract class with all methods abstract - Practical Example
The only practical approach i think is that Abstract class can hold state. So you can have inside properties with access level protected, and you can make protected abstract methods that in interface you can't cause all are public. A practical example could be for example this, the protected method in java has 'inheritance access' and 'package access'. public interface Operation{ void operate(); } public abstract class AbstractClase implements Operation{ protected Operation delegate; public AbstractClase(Operation delegate){ this.delegate=delegate; } //delegate implementation responsability to children protected abstract doSomething(); } The downside of using abstract class is that you loss the possibility to extends of something else too.

Categories : Java

Access to inherited children's variables of abstract class from another children of same abstract class
Your code works for me! I do not get a fatal error. The only thing I get is a notice because of the typo inside $this->variable in the child2 class. The original variable is incorrectly spelled "varialbe", but used consistently. Fixing the typo lets the code run completely error-free. So you fail to demonstrate the problem. Update your question if you find why the issue isn't included in your code. It must be somewhere else. And make sure you actually run your code before using it as an example, and that it has the problem you describe.

Categories : PHP

Spring MVC Web framework, I cannot call a method from my controller class
I didn't see any use of spring:url in your JSP. It is the classic way of composing url with Spring MVC, because it will automatically add the base url to your application. You didn't mention any mapping to your controller so it will be reached throw root url '/', and if you want to reach your method 'doActions()' you have to use : <spring:url value="/success.htm" var="success"/> and then : <a href="${success}>toSuccess</a> Also, you should use JSPX, not JSP page, it is the recommend way with Spring MVC.

Categories : Spring

ways to inject a object of a class in spring controller?
Actually, injection with xml and annotation is same behind the scene. Xml is old fashion while annotations are newer. Basically, there are 2 types of injection types. byName Autowiring by property name. Spring container looks at the properties of the beans on which autowire attribute is set to byName in the XML configuration file. It then tries to match and wire its properties with the beans defined by the same names in the configuration file. You can give explicit names to beans both with xml and annotation. @Service("BeanName") @Component("BeanName") @Controller("BeanName") <bean name="BeanName" class="someclass"></bean> and inject beans by using @Qualifier annotation. @Autowired @Qualifier("BeanName") and with xml <bean id="MyBean2" class="MyBean2

Categories : Java

How to redirect to an ASPX page using a C# Class?
Have a look at How to: Redirect Users to Another Page Also HttpResponse.Redirect Method Redirects a client to a new URL. Specifies the new URL and whether execution of the current page should terminate.

Categories : C#

Abstract class inheriting from non-abstract in .NET?
Of course it can. object is not abstract (although IMO it should be), so every abstract class is actually an example of this: abstract class Foo {} // tada! - note this is implicitly : object You would need to further subclass it as non-abstract before you could create an instance of it, though. But to be explicit: class Foo {} // fine abstract class Bar : Foo {} // fine class Blap : Bar {} // fine

Categories : Dotnet

Use of an abstract class without any abstract methods
You can make a class as abstract ,even if you don't want to implement all of the interface methods that the class implements. According to java docs. It was noted that a class that implements an interface must implement all of the interface's methods. It is possible, however, to define a class that does not implement all of the interface methods, provided that the class is declared to be abstract. Any way you can't instantiate a class that declared with abstract.

Categories : Java

php abstract class property from another abstract class
You cant call a method when you are declaring a class variable, you will need to do public $db = null public function __construct() { $this->db = Bdd::getInstance(); } The only gotcha with this is when you extend this class and you need to create a constructor you will need to call this constructor as well by doing parent::__construct();

Categories : PHP

Beforeunload is not working to redirect user to another page, how can I redirect user to another page/url when he attempts to close a window/tab?
*Don't do it* But it is possible with the user's permission; you can achieve something like this (took me a while to find a website that was happy in a frame) window.onbeforeunload = function () { window.setTimeout(function () { // escape function context window.location = 'http://bbc.co.uk'; }, 0); window.onbeforeunload = null; // necessary to prevent infinite loop // that kills your browser return 'Press "Stay On Page" to go to BBC website!'; // pressing leave will still leave, but the GET may be fired first anyway } Demo

Categories : Javascript

Class template where variable class derives from certain abstract class
Use std::is_base_of: template <class A> class B { static_assert(std::is_base_of<C, A>::value , "A must derive from C"); //... }; Note that is_base_of<C, C>::value is true, so you may want to also use std::is_same to ensure A is not actually C itself: static_assert(std::is_base_of<C, A>::value && !std::is_same<C, A>::value , "A must derive from C");

Categories : C++

Redirect to the original URL after signin using Spring Social, Spring security?
Have you actually tried it to see if it works? Spring security does this automatically. If you are an anonymous user and attempt to access a resource that requires a certain permission, spring security will store the attempted URL and redirect you to the login page. After successful login it fetches the attempted URL back and redirects you there.

Categories : Java

How to redirect /page/index page to /page (and /page to /page/) in Ruby on Rails?
If you don't want to cause a full reload of the page, then you should not use "redirect" in your routes, as that simply issues a browser redirect. That would cause Rails to issue a 301 "Moved Permanently". That essentially means "there is a /page/index route but it's a mistake, we don't use it anymore, please go to /page instead and never come back here." If that is the case then that is what you want to do. If you're using Passenger and will continue to use Passenger, it would be more efficient to put an Apache redirect rule in the htaccess file. It also seems strange that this is even an issue. How have /page/index, /page, and /page/ emerged in the wild as URLs that all point to the same index#index action? What is this index controller? The usual thing is to have, say, a PagesControlle

Categories : Ruby On Rails

Accessing Protected Variable Of An Instance Of A Class That Extends An Abstract Base Class?
The protected keyword makes things visible within the same package. Which is the case, because both of your classes are in package mypackage. Here is a nice table, taken from Oracle.com:

Categories : Java

Creating an array of pointers of derivative class objects. C++. Abstract base class
Since there isn't a question: make sure your base class has a virtual destructor. Without a virtual destructor you won't be able to easily delete the objects. To maintain the objects I would create a simple version of std::unique_ptr if I have to write it myself (well, for my own standard library implementation I, obviously, have an implementation anyway which I'd think I should be able to use...).

Categories : C++

I know, we can not instantiate either an interface or an abstract class in java except using anonymous class method but what is the reason behind it?
You can't instantiate an interface or an abstract class because it would defy the object oriented model. Interfaces represent contracts - the promise that the implementer of an interface will be able to do all these things, fulfill the contract. Abstract classes are a similar idea, in that they represent an unfulfilled contract, a promise to be able to do things, except unlike interfaces they have some of their functions or fields defined but need filling in before they can used. Simply, in a good object oriented program, you should never want to instantiate an abstract class or interface. If you do, the design is probably wrong. (Anonymous classes are actually non-abstract instantiations, just that they don't need to be given a name, so they appear to be 'raw interfaces' but they're a

Categories : Java

Designing a writer for different file formats in C# (interface vs. class vs. abstract class)
All of your options look reasonable and equally good. The choise shoud be based on the other requirements for your system. If you want to add formats in the future, and multiple people will write them, then one class per writer seems a better option, as they would be better separated, you can load them dynamically and test independently. If you want to call these methods from some powershell script, multiple static methods in the same class may be a simpler and more convinient solution.

Categories : C#

How does a method in an abstract base class call the constructor from a derived class?
A function can return an instance of whatever you want it to ;) In this case, an instance of 256Managed is still castable to SHA256 Something like this is entirely feasible: public class SHA256Managed { public static SHA256 Create() { return new SHA256Managed(); } }

Categories : C#

Abstract class calling a method from the wrong child class
It sounds to me like you are using static methods. Otherwise the problem you describe cannot reasonably occur. You wrote, "on_save_changes() does not know which child class to call the abstract method child_save_changes() from". But ordinary (i.e., non-static) methods are not called from classes, they are called from objects. And every object knows exactly which class it belongs to, and thus there can never be confusion about which method is meant to be called. Static methods, on the other hand, are not designed to work with inheritance hierarchies like that. I would personally recommend refactoring your code and turn them into non-static ones, but if you do not want to do that, you may be able to make it work using late static binding.

Categories : PHP

Is it possible to pass the abstract class's object as argument to an instance of a class?
if you are asking if a method can take an abstract object like this: private void DoSomething(AEnvironmentSetting a) then yes, it can, and you can use every property and method there is in the abstract class including calling abstract method. however, whoever calls this method will have to send an instance of a calss inherits the abstract class like so: DatabaseDataDealer d = new DatabaseDataDealer (); DoSomething(d); and if an abstract method will be call from DoSomething then implementation of DatabaseDataDealer will be called in the constructor you can call the base and you will get to the abstract constructor. in the end let me just say the best way to learn this is to try. compile and run your code and put a break point to see how it goes and through which steps

Categories : C#

How to dynamically create an anonymous class that extends an abstract class in PHP?
You do have access ev(a|i)l. If you used traits to compose your class it COULD be possible to do this. <?php trait Constructor { public function __construct() { echo __METHOD__, PHP_EOL; } } trait Runner { public function run() { echo __METHOD__, PHP_EOL; } } trait Destructor { public function __destruct() { echo __METHOD__, PHP_EOL; } } $className = 'Thread'; $traits = ['Constructor','Destructor','Runner',]; $class = sprintf('class %s { use %s; }', $className, implode(', ', $traits)); eval($class); $thread = new $className; $thread->run(); This outputs ... Constructor::__construct Runner::run Destructor::__destruct So you CAN, but not sure if you SHOULD.

Categories : PHP

Is this code instantiating or extending an abstract class without creating a new class?
It almost looks like the code extends WindowAdapter or overrides the windowClosing method This is exactly what's happening. but how is that possible without writing a new class? In fact, the code is creating a new (anonymous) class. It's just that the syntax is different to what you've come across so far. Take a look at the tutorial. For a discussion of how anonymous classes are used, see How are Anonymous (inner) classes used in Java?

Categories : Java

getClass() in abstract class returns random implementation class
Well, you bind to IA ... and there are two IA services (ImplAA and ImplAB). So, why on earth would DS use a different service instance for bindToAA than it does for bindToAB? You only declared to require an IA? Both bind methods require 0 or 1 IA instance so any of the two services matches the bill, in those cases it is better to take just one since the requirer (SomeClass) doesn't seem to care about the difference. No the big question in my head is, why on earth would you want to depend on the instance? The whole purpose of OSGi is to keep instances hidden away. If you have a dependency requirement, then express this, this is the OSGi way. No if you just want to print the services, make the cardinality MULTIPLE and put the services in a list. In that case you express the interest in AL

Categories : Java

Abstract class methods implementation with subclasses of an other base class
No, it wouldn't make sense. Think about the following scenario - you have a container (vector/set w/e) of Algorithm* type objects and a function that takes this container and a InputData* in as an input and then iterate over them and call insertData(in) on each of the objects in the container, this of course should work properly, but if one of the objects in your container is of type Algorithm1 what will happen then?

Categories : C++

implementing get/set property in a concrete class which inherits from an abstract class
Interesting, I got it to work by simply defining the properties block before the methods block in the subclass (the order seems to matter here): classdef subClass < superClass properties a; end methods function val = get.a(obj) val = obj.a; end end end I think this is an issue with the MATLAB parser, perhaps you should file a bug report.

Categories : Matlab

Nest Classes using Abstract class? (As well as protect/hide a class)?
Answer #1: Instead of ... //Member variables... private string _emulation = ""; private string _application = ""; private string _database = ""; //Get/Set properties... public string Emulation { get {return _emulation;} set {_emulation = value;} } public string Application { get {return _application;} set {_application = value;} } public string Database { get {return _database;} set {_database = value;} } Your properties can be expressed this way instead (it is equivalent, except for the initialization to "", which can be done if needed in a constructor instead): public string Emulation { get; set; } public string Application { get; set; } public string Database { get; set; } Answer 2/3: Abstractness and inner classes are not used to limit the visibility of classes to

Categories : C#



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.