struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Raghuveer Rawat" <>
Subject [Struts2] Ajax anchor tag problem
Date Mon, 21 Jan 2008 19:25:27 GMT
Hi, I have a requirement where only logged in users are allowed to put their
comment. I have implemented that form with struts2 ajax theme...anchor has

If logged in user  puts his comment then  everything  works fine
perfectly..I am able to see text message returned from action in target

But when a user who is not logged in and try to put this comment..I want to
redirect user to login page..*but there what is happening here is that login
page is also streaming back and it is opening in target div..*

Any idea how to redirect user to login page..

Below is my action class method..

public String addComment() {
            UserTO userTo = null;
            Object user = this.getSession().get("user");
            if(user == null){
                return Action.LOGIN;
                userTo = (UserTO) user;

            HttpServletResponse response = ServletActionContext.getResponse
            //inputStream = new StringBufferInputStream("Comment Posted
            String successMsg = "Thanks for posting comment. Your comment
has been added successfully.";
            byte[] contents = successMsg.getBytes();

        }catch(Exception ex){
            LOG.error("Exception in myArticles():"+ ex);
            return Action.ERROR;
        return null;

This is my comment form...

               <div id='commentResponse'>
            <s:form action="comments_addComment"  method="post" >

            <table width="583" border="0" cellspacing="2" cellpadding="2">
                  <td width="99" align="left"><strong>Your Comments</strong>
                  <td width="470" align="left">
                    <s:textarea name="commentTo.comments"  rows="5"
                    <s:hidden name="articleId" value="${article.articleId
                  <td align="left">&nbsp;</td>
                  <td width="470" align="left">

                  <s:a theme="ajax" targets="commentResponse">Add

Below is struts.xml entry..I am using tiles and default results are tile
definitions....I also tried using redirect-action and redirect but that also
give same problem..

         <action name="comments_*" method="{1}" class="
            <result name="login">login</result>


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message