[Struts]output javascript in struts perform()

S

sin

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");

}
}

===========================================================
 
S

Sudsy

sin wrote:
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...
 
A

Andrew Thompson

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( said:
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. ;-)
 
S

Sudsy

Andrew said:
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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top