[Struts]output javascript in struts perform()

Discussion in 'Java' started by sin, Feb 21, 2004.

  1. sin

    sin Guest

    I would like to output javascript in struts perform() like in servlet.
    But I failed to get the message, could you any one give me some ideas?

    ==========================================================
    public class LoginAction extends Action implements Serializable{
    public ActionForward perform(ActionMapping actionMapping,
    ActionForm actionForm,
    HttpServletRequest httpServletRequest,
    HttpServletResponse httpServletResponse) {

    if(db_password.equalsIgnoreCase("") ){
    PrintWriter out = httpServletResponse.getWriter();
    out.println("<script language=JavaScript>");
    out.println("<!--");
    out.println("alert(\"Auth Fail!\");");
    out.println("-->");
    out.println("<script>");

    return actionMapping.findForward("failure");
    }

    return actionMapping.findForward("failure");

    }
    }

    ===========================================================
     
    sin, Feb 21, 2004
    #1
    1. Advertising

  2. sin

    Sudsy Guest

    sin wrote:
    <snip>
    > out.println("<script language=JavaScript>");
    > out.println("<!--");
    > out.println("alert(\"Auth Fail!\");");
    > out.println("-->");
    > out.println("<script>");

    </snip>

    Perhaps a typo or an error in C&P, but shouldn't that line be
    out.println("</script");
    ?
    Little things mean a lot...
     
    Sudsy, Feb 22, 2004
    #2
    1. Advertising

  3. sin wrote:

    Sudsy pointed out the unclosed script tag,
    but I will suggest futher changes..

    > if(db_password.equalsIgnoreCase("") ){
    > PrintWriter out = httpServletResponse.getWriter();
    > out.println("<script language=JavaScript>");


    'language' has been deprecated in 4.01,
    instead use..

    out.println("<script type='text/javascript'>");

    > out.println("<!--");
    > out.println("alert(\"Auth Fail!\");");


    You could use single quotes for this..
    out.println("alert('Auth Fail!');");

    > out.println("-->");
    > out.println("<script>");


    and of course..
    out.println("</script>");


    Which probably solved the
    immediate problem. ;-)

    --
    Andrew Thompson
    * http://www.PhySci.org/ Open-source software suite
    * http://www.PhySci.org/codes/ Web & IT Help
    * http://www.1point1C.org/ Science & Technology
     
    Andrew Thompson, Feb 22, 2004
    #3
  4. sin

    Sudsy Guest

    Andrew Thompson wrote:
    > sin wrote:
    >
    > Sudsy pointed out the unclosed script tag,
    > but I will suggest futher changes..


    Andrew makes many unsolicited suggestions, all of which
    are valid and all of which are being provided pro bono.
    Send him some money via PayPal or some other mechanism:
    he's saved you a bundle!
    I don't know about the rest of you, but my 'net access
    isn't free. Kudos to the providers of solutions are fine
    but micro-payments would go a long way to assisting the
    people who shoulder the burden of both investigating
    technologies and providing solutions.
    The injection of the cost of a pack of ciggies or a
    six-pack of beer wouldn't be an onerous cost for info
    which saves countless hours of research, eh?
     
    Sudsy, Feb 22, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ALuPin
    Replies:
    13
    Views:
    6,424
    mouna
    Nov 27, 2008
  2. z0mb1e_fr
    Replies:
    2
    Views:
    743
    z0mb1e_fr
    Dec 3, 2003
  3. Replies:
    2
    Views:
    506
    Dimitre Novatchev
    May 19, 2005
  4. William Payne

    Perform output if stream is good

    William Payne, Sep 25, 2004, in forum: C++
    Replies:
    6
    Views:
    382
    Ron Natalie
    Sep 27, 2004
  5. Replies:
    2
    Views:
    1,819
Loading...

Share This Page