Deprecated: Creation of dynamic property wpdb::$categories is deprecated in /home2/learnera/public_html/tech/wp-includes/wp-db.php on line 760

Deprecated: Creation of dynamic property wpdb::$post2cat is deprecated in /home2/learnera/public_html/tech/wp-includes/wp-db.php on line 760

Deprecated: Creation of dynamic property wpdb::$link2cat is deprecated in /home2/learnera/public_html/tech/wp-includes/wp-db.php on line 760

Deprecated: Creation of dynamic property WPtouchProFour::$settings_object is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/wptouch/core/class-wptouch-pro.php on line 82

Deprecated: Automatic conversion of false to array is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/wptouch/core/admin-load.php on line 70

Deprecated: Creation of dynamic property WP_Block_Type::$skip_inner_blocks is deprecated in /home2/learnera/public_html/tech/wp-includes/class-wp-block-type.php on line 391

Deprecated: Creation of dynamic property WP_Block_Type::$skip_inner_blocks is deprecated in /home2/learnera/public_html/tech/wp-includes/class-wp-block-type.php on line 391

Deprecated: Creation of dynamic property Advanced_Editor_Tools::$toolbar_classic_block is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/tinymce-advanced/tinymce-advanced.php on line 347

Deprecated: Creation of dynamic property Advanced_Editor_Tools::$toolbar_block is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/tinymce-advanced/tinymce-advanced.php on line 349

Deprecated: Creation of dynamic property Advanced_Editor_Tools::$toolbar_block_side is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/tinymce-advanced/tinymce-advanced.php on line 350

Deprecated: Creation of dynamic property Advanced_Editor_Tools::$panels_block is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/tinymce-advanced/tinymce-advanced.php on line 351

Deprecated: Creation of dynamic property Advanced_Editor_Tools::$used_block_buttons is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/tinymce-advanced/tinymce-advanced.php on line 354

Deprecated: Creation of dynamic property YARPP::$is_custom_template is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/yet-another-related-posts-plugin/classes/YARPP_Core.php on line 56

Deprecated: Creation of dynamic property YARPP::$db_options is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/yet-another-related-posts-plugin/classes/YARPP_Core.php on line 69

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /home2/learnera/public_html/tech/wp-includes/class-wp-term-query.php on line 1118

Deprecated: Return type of Requests_Cookie_Jar::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home2/learnera/public_html/tech/wp-includes/Requests/Cookie/Jar.php on line 63

Deprecated: Return type of Requests_Cookie_Jar::offsetGet($key) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home2/learnera/public_html/tech/wp-includes/Requests/Cookie/Jar.php on line 73

Deprecated: Return type of Requests_Cookie_Jar::offsetSet($key, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home2/learnera/public_html/tech/wp-includes/Requests/Cookie/Jar.php on line 89

Deprecated: Return type of Requests_Cookie_Jar::offsetUnset($key) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home2/learnera/public_html/tech/wp-includes/Requests/Cookie/Jar.php on line 102

Deprecated: Return type of Requests_Cookie_Jar::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home2/learnera/public_html/tech/wp-includes/Requests/Cookie/Jar.php on line 111

Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home2/learnera/public_html/tech/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 40

Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::offsetGet($key) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home2/learnera/public_html/tech/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 51

Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::offsetSet($key, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home2/learnera/public_html/tech/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 68

Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::offsetUnset($key) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home2/learnera/public_html/tech/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 82

Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home2/learnera/public_html/tech/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 91

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /home2/learnera/public_html/tech/wp-includes/class-wp-term-query.php on line 1118

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /home2/learnera/public_html/tech/wp-includes/class-wp-term-query.php on line 1118
Custom URL in Struts2 for each User | Rajesh

Custom URL in Struts2 for each User


Deprecated: Creation of dynamic property WPDM\Package\Package::$post_author is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/download-manager/src/Package/PackageController.php on line 375

Deprecated: Creation of dynamic property WPDM\Package\Package::$post_date is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/download-manager/src/Package/PackageController.php on line 375

Deprecated: Creation of dynamic property WPDM\Package\Package::$post_date_gmt is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/download-manager/src/Package/PackageController.php on line 375

Deprecated: Creation of dynamic property WPDM\Package\Package::$post_content is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/download-manager/src/Package/PackageController.php on line 375

Deprecated: Creation of dynamic property WPDM\Package\Package::$post_title is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/download-manager/src/Package/PackageController.php on line 375

Deprecated: Creation of dynamic property WPDM\Package\Package::$post_excerpt is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/download-manager/src/Package/PackageController.php on line 375

Deprecated: Creation of dynamic property WPDM\Package\Package::$comment_status is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/download-manager/src/Package/PackageController.php on line 375

Deprecated: Creation of dynamic property WPDM\Package\Package::$ping_status is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/download-manager/src/Package/PackageController.php on line 375

Deprecated: Creation of dynamic property WPDM\Package\Package::$post_password is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/download-manager/src/Package/PackageController.php on line 375

Deprecated: Creation of dynamic property WPDM\Package\Package::$post_name is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/download-manager/src/Package/PackageController.php on line 375

Deprecated: Creation of dynamic property WPDM\Package\Package::$to_ping is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/download-manager/src/Package/PackageController.php on line 375

Deprecated: Creation of dynamic property WPDM\Package\Package::$pinged is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/download-manager/src/Package/PackageController.php on line 375

Deprecated: Creation of dynamic property WPDM\Package\Package::$post_modified is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/download-manager/src/Package/PackageController.php on line 375

Deprecated: Creation of dynamic property WPDM\Package\Package::$post_modified_gmt is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/download-manager/src/Package/PackageController.php on line 375

Deprecated: Creation of dynamic property WPDM\Package\Package::$post_content_filtered is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/download-manager/src/Package/PackageController.php on line 375

Deprecated: Creation of dynamic property WPDM\Package\Package::$post_parent is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/download-manager/src/Package/PackageController.php on line 375

Deprecated: Creation of dynamic property WPDM\Package\Package::$guid is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/download-manager/src/Package/PackageController.php on line 375

Deprecated: Creation of dynamic property WPDM\Package\Package::$menu_order is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/download-manager/src/Package/PackageController.php on line 375

Deprecated: Creation of dynamic property WPDM\Package\Package::$post_type is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/download-manager/src/Package/PackageController.php on line 375

Deprecated: Creation of dynamic property WPDM\Package\Package::$post_mime_type is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/download-manager/src/Package/PackageController.php on line 375

Deprecated: Creation of dynamic property WPDM\Package\Package::$comment_count is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/download-manager/src/Package/PackageController.php on line 375

Deprecated: Creation of dynamic property WPDM\Package\Package::$filter is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/download-manager/src/Package/PackageController.php on line 375

Deprecated: Creation of dynamic property WPDM\Package\Package::$author_name is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/download-manager/src/Package/PackageController.php on line 375

Deprecated: Creation of dynamic property WPDM\Package\Package::$author_profile_url is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/download-manager/src/Package/PackageController.php on line 375

Deprecated: Creation of dynamic property WPDM\Package\Package::$avatar_url is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/download-manager/src/Package/PackageController.php on line 375

Deprecated: Creation of dynamic property WPDM\Package\Package::$avatar is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/download-manager/src/Package/PackageController.php on line 375

Deprecated: Creation of dynamic property WPDM\Package\Package::$thumb is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/download-manager/src/Package/PackageController.php on line 375

Deprecated: Creation of dynamic property WPDM\Package\Package::$preview is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/download-manager/src/Package/PackageController.php on line 375

Deprecated: Creation of dynamic property WPDM\Package\Package::$file_count is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/download-manager/src/Package/PackageController.php on line 375

Deprecated: Creation of dynamic property WPDM\Package\Package::$page_url is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/download-manager/src/Package/PackageController.php on line 375

Deprecated: Creation of dynamic property WPDM\Package\Package::$page_link is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/download-manager/src/Package/PackageController.php on line 375

Deprecated: Creation of dynamic property WPDM\Package\Package::$page_url_qr is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/download-manager/src/Package/PackageController.php on line 375

Deprecated: Creation of dynamic property WPDM\Package\Package::$btnclass is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/download-manager/src/Package/PackageController.php on line 375

Deprecated: Creation of dynamic property WPDM\Package\Package::$file_size is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/download-manager/src/Package/PackageController.php on line 375

Deprecated: Creation of dynamic property WPDM\Package\Package::$file_type_icon is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/download-manager/src/Package/PackageController.php on line 375

Deprecated: Creation of dynamic property WPDM\Package\Package::$download_url is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/download-manager/src/Package/PackageController.php on line 375

Deprecated: Creation of dynamic property WPDM\Package\Package::$download_link is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/download-manager/src/Package/PackageController.php on line 375

Deprecated: Creation of dynamic property WPDM\Package\Package::$download_link_extended is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/download-manager/src/Package/PackageController.php on line 375

Deprecated: Creation of dynamic property WPDM\Package\Package::$download_link_popup is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/download-manager/src/Package/PackageController.php on line 375

Deprecated: Creation of dynamic property WPDM\Package\Package::$formatted is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/download-manager/src/Package/PackageController.php on line 375

Deprecated: Creation of dynamic property WPDM\Package\Package::$__template is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/download-manager/src/Package/PackageController.php on line 375

Deprecated: Creation of dynamic property WPDM\Package\Package::$__template_type is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/download-manager/src/Package/PackageController.php on line 375

Deprecated: Creation of dynamic property WP_Query::$yarpp_cache_type is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/yet-another-related-posts-plugin/classes/YARPP_Cache.php on line 30

Deprecated: Creation of dynamic property WP_Post::$score is deprecated in /home2/learnera/public_html/tech/wp-includes/class-wp-post.php on line 266

Deprecated: Creation of dynamic property WP_Post::$score is deprecated in /home2/learnera/public_html/tech/wp-includes/class-wp-post.php on line 266

Deprecated: Creation of dynamic property WP_Post::$score is deprecated in /home2/learnera/public_html/tech/wp-includes/class-wp-post.php on line 266

Deprecated: Creation of dynamic property WP_Post::$score is deprecated in /home2/learnera/public_html/tech/wp-includes/class-wp-post.php on line 266

Deprecated: Creation of dynamic property WP_Post::$score is deprecated in /home2/learnera/public_html/tech/wp-includes/class-wp-post.php on line 266

Deprecated: Creation of dynamic property WP_Post::$score is deprecated in /home2/learnera/public_html/tech/wp-includes/class-wp-post.php on line 266

Deprecated: Creation of dynamic property WP_Post::$score is deprecated in /home2/learnera/public_html/tech/wp-includes/class-wp-post.php on line 266

Deprecated: Creation of dynamic property WP_Post::$score is deprecated in /home2/learnera/public_html/tech/wp-includes/class-wp-post.php on line 266

Deprecated: Creation of dynamic property WP_Post::$score is deprecated in /home2/learnera/public_html/tech/wp-includes/class-wp-post.php on line 266

Deprecated: Creation of dynamic property WP_Post::$score is deprecated in /home2/learnera/public_html/tech/wp-includes/class-wp-post.php on line 266

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /home2/learnera/public_html/tech/wp-includes/class-wp-term-query.php on line 1118

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /home2/learnera/public_html/tech/wp-includes/class-wp-term-query.php on line 1118

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /home2/learnera/public_html/tech/wp-includes/class-wp-term-query.php on line 1118

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /home2/learnera/public_html/tech/wp-includes/class-wp-term-query.php on line 1118

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /home2/learnera/public_html/tech/wp-includes/class-wp-term-query.php on line 1118

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /home2/learnera/public_html/tech/wp-includes/class-wp-term-query.php on line 1118

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /home2/learnera/public_html/tech/wp-includes/class-wp-term-query.php on line 1118

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /home2/learnera/public_html/tech/wp-includes/class-wp-term-query.php on line 1118

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /home2/learnera/public_html/tech/wp-includes/class-wp-term-query.php on line 1118

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /home2/learnera/public_html/tech/wp-includes/class-wp-term-query.php on line 1118

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /home2/learnera/public_html/tech/wp-includes/class-wp-term-query.php on line 1118

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /home2/learnera/public_html/tech/wp-includes/class-wp-term-query.php on line 1118

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /home2/learnera/public_html/tech/wp-includes/class-wp-term-query.php on line 1118

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /home2/learnera/public_html/tech/wp-includes/class-wp-term-query.php on line 1118

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /home2/learnera/public_html/tech/wp-includes/class-wp-term-query.php on line 1118

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /home2/learnera/public_html/tech/wp-includes/class-wp-term-query.php on line 1118

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /home2/learnera/public_html/tech/wp-includes/class-wp-term-query.php on line 1118

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /home2/learnera/public_html/tech/wp-includes/class-wp-term-query.php on line 1118

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /home2/learnera/public_html/tech/wp-includes/class-wp-term-query.php on line 1118

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /home2/learnera/public_html/tech/wp-includes/class-wp-term-query.php on line 1118

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /home2/learnera/public_html/tech/wp-includes/class-wp-term-query.php on line 1118

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /home2/learnera/public_html/tech/wp-includes/class-wp-term-query.php on line 1118

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /home2/learnera/public_html/tech/wp-includes/class-wp-term-query.php on line 1118

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /home2/learnera/public_html/tech/wp-includes/class-wp-term-query.php on line 1118

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /home2/learnera/public_html/tech/wp-includes/class-wp-term-query.php on line 1118

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /home2/learnera/public_html/tech/wp-includes/class-wp-term-query.php on line 1118

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /home2/learnera/public_html/tech/wp-includes/class-wp-term-query.php on line 1118

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /home2/learnera/public_html/tech/wp-includes/class-wp-term-query.php on line 1118

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /home2/learnera/public_html/tech/wp-includes/class-wp-term-query.php on line 1118

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /home2/learnera/public_html/tech/wp-includes/class-wp-term-query.php on line 1118

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /home2/learnera/public_html/tech/wp-includes/class-wp-term-query.php on line 1118

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /home2/learnera/public_html/tech/wp-includes/class-wp-term-query.php on line 1118

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /home2/learnera/public_html/tech/wp-includes/class-wp-term-query.php on line 1118

In this tutorial we will see how to assign custom URL for each user logged in Struts2. For example like ‘www.gmail.com/rajesh’  for user rajesh and ‘www.gmail.com/kumar’  for user kumar.

I assume that you already have a basic knowledge over struts 2 framework setup and simple Struts2 application. If you are not familiar please refer Struts2 Introduction and HelloWorld application.

To create custom URL for each user first we have to set the below constants in the struts.xml.

<constant name="struts.action.extension" value=",,action" />
<constant name="struts.mapper.alwaysSelectFullNamespace" value="false" />
<constant name="struts.enable.SlashesInActionNames" value="true" />
<constant name="struts.patternMatcher" value="regex" />

The first constant struts.action.extension  is to disable the default .action extension from the URL pattern. The next two constants struts.mapper.alwaysSelectFullNamespace  and struts.enable.SlashesInActionNames for transfering the parameter from the URL. The last one struts.patternMatcher is to use regular expression in the action names (For example <action name=”Lost*do”>).

Next is we have to map the request to an action. To do this create an action like below in struts.xml.

<action name="{username}" class="com.rajesh.struts2.CustomURL" method="customUrl">
    <result name="success">welcome.jsp</result>
</action>

In the above code we mapped the string whichever comes next to the application context to the field username. For example if the request is http://localhost:8080/CustomURL/rajesh  the framework will assign the value ‘rajesh’ to username field and then will proceed like normal struts2 flow. But one important thing is it will not accept slash in that. For example if the request is http://localhost:8080/CustomURL/test/rajesh the framework will not call the above action. Because the request is for inside a package test. See the finalized code of struts.xml below.

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.action.extension" value=",,action" />
    <constant name="struts.mapper.alwaysSelectFullNamespace" value="false" />
    <constant name="struts.enable.SlashesInActionNames" value="true" />
    <constant name="struts.patternMatcher" value="regex" />

    <package name="default" namespace="/" extends="struts-default">

        <action name="">
            <result name="success">home.jsp</result>
        </action>

        <action name="{username}" class="com.rajesh.struts2.CustomURL" method="customUrl">
            <result name="success">welcome.jsp</result>
        </action>

    </package>
</struts>

In the above code we added one more action with empty name “”. It is for the index page. So when we type simply the url http://localhost:8080/CustomURL the home.jsp will be displayed. See our home.jsp below.See our welcome.jsp below.

welcome.jsp

<html>

<head>
    <title>Struts 2 Custom URL</title>
    <script src="jquery-1.11.1.min.js"></script>
    <script>
        function myFunction() {
            window.location.href = $("#username").val();
        }
    </script>
</head>

<body>
    <h1>Struts 2 Custom URL</h1>
    <h3>Enter User Name</h3>
    <input type="text" id="username" />
    <input type="submit" value="Login" onclick="myFunction()" />
</body>

</html>

See our action class CustomURL.java below

CustomURL.java

package com.rajesh.struts2;

import com.opensymphony.xwork2.ActionSupport;

public class CustomURL extends ActionSupport {

    private static final long serialVersionUID = -4337790298641431230L;

    private String username;

    public String getUsername() {
        System.out.println("Inside Getter");
        return username;
    }

    public void setUsername(String username) {
        System.out.println("Inside Setter " + username);
        this.username = username;
    }

    public String customUrl() {
        return SUCCESS;
    }
}

That’s all. Simply place all the above codes in respective files and run.

custom_url_demo_1
custom_url_demo_2
For the above example I have created a complete .war file with source code. Download and just place under Apache web apps folder and run.

If you face any issues while execution please post in comments or send email to rajeshmepco@gmail.com


Deprecated: Creation of dynamic property WP_Term::$cat_ID is deprecated in /home2/learnera/public_html/tech/wp-includes/category.php on line 378

Deprecated: Creation of dynamic property WP_Term::$category_count is deprecated in /home2/learnera/public_html/tech/wp-includes/category.php on line 379

Deprecated: Creation of dynamic property WP_Term::$category_description is deprecated in /home2/learnera/public_html/tech/wp-includes/category.php on line 380

Deprecated: Creation of dynamic property WP_Term::$cat_name is deprecated in /home2/learnera/public_html/tech/wp-includes/category.php on line 381

Deprecated: Creation of dynamic property WP_Term::$category_nicename is deprecated in /home2/learnera/public_html/tech/wp-includes/category.php on line 382

Deprecated: Creation of dynamic property WP_Term::$category_parent is deprecated in /home2/learnera/public_html/tech/wp-includes/category.php on line 383
This entry was posted in Struts2 and tagged . Bookmark the permalink.

Deprecated: Creation of dynamic property WP_Query::$comments_by_type is deprecated in /home2/learnera/public_html/tech/wp-includes/comment-template.php on line 1527

One Response to "Custom URL in Struts2 for each User"

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.