how to redirect the page in struts

I have given username and password in text field. that is index.jsp

if the condition is correct go to view.jsp. if the condition is wrong go to index.jsp. then how to redirect the same page. please tell me

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception

{

// TODO: Write method body

javax.sql.DataSource dataSource;

java.sql.Connection myConnection=null;

Mgf = (MakeGuessForm)form;

ActionForward forward = mapping.findForward("index");

try

{

dataSource = getDataSource(request);

myConnection = dataSource.getConnection();

Statement stmt=myConnection.createStatement();

admnName = Mgf.getadmin_name() ;// Get the User Mail

admnPwd = Mgf.getadmin_password();

String Query = ("select * from admin " ) ;

rst = stmt.executeQuery(Query);

while(rst.next())

{

admn = rst.getString(1);

pwd = rst.getString(2);

}

}

catch (Exception e) {

getServlet().log("Connection.close", e);

}

if( (admnName.equals(admn)) && (admnPwd.equals(pwd)))

{

request.setAttribute("kk",admnName);

forward = mapping.findForward("view");

}

else

{

forward = mapping.findForward("index");

}

return(forward);

}

}

regards pooja

[1469 byte] By [sherin_poojaa] at [2007-10-2 18:42:02]
# 1
can i have ur yahoo id? plz
bobza at 2007-7-13 20:04:15 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

hi,

ur Action class is correct. may be the problem is with ur struts-configuration.xml file.

u given tha,

if( (admnName.equals(admn)) && (admnPwd.equals(pwd)))

{

request.setAttribute("kk",admnName);

forward = mapping.findForward("view");

}

else

{

forward = mapping.findForward("index");

}

return(forward);

And check ur struts-config.xml entry should match with this,

<action-mappings>

<action path="/xxx" type="xxx">

<forward name="view" path="/ur path/view.jsp" />

<forward name="index" path="/ur path/index.jsp" />

</action>

</action-mappings>

PavanKumarGuptaa at 2007-7-13 20:04:15 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
> can i have ur yahoo id? plzThis is not a dating site.
aniseeda at 2007-7-13 20:04:15 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

Normal Jsp page we send this procedure :

admincheck.jsp:

<% if( (admnName != admn) && (admnPwd !=pwd )) {%>

<jsp:forward page="index.jsp">

<jsp:param name="errMsg"

value="Sorry Your UserName and Password is Mismatch" />

</jsp:forward>

<% } %>

index.jsp

<%

String error = request.getParameter("errMsg");

if(error != null)

out.println("

<font color=FF0000 size = 3>" + error + "</font>

");

%>

In Struts How to send error message.Will you help me what is the procedure .

if( (admnName.equals(admn)) && (admnPwd.equals(pwd)))

{

request.setAttribute("kk",admnName);

return(mapping.findForward("view"));

}

else

{

return(mapping.findForward("index"));

}

Please help me.

sherin_poojaa at 2007-7-13 20:04:15 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

hi,

if u want to send the static error message, u can send it through the StrutsConfig.xml file.

else

{

return(mapping.findForward("index"));

}

In forward statement use this syntax,,

<actionmappings>

<action name="" path="">

<foward name="index" path="/Index.jsp?errMsg=Sorry your UserName and Password is Mismatch" />

</action>

</actionmappings>

In other way, if u want to send the dynamic error msg,

else

{

request.setAttribute("errMsg", " ur msg");

return(mapping.findForward("index"));

}

these two ways will work.

regards,

pavan.

PavanKumarGuptaa at 2007-7-13 20:04:15 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
Hi Pavan thank you for ur help. Please tell me how to print variable(errMsg=Sorry your UserName and Password is Mismatch") in jsp page. please tell me.thanks in Advanceregards pooja
sherin_poojaa at 2007-7-13 20:04:15 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
use <%=(String)request.getAttribute("errMsg")%>on jsp.
rahul_devpuria at 2007-7-13 20:04:15 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8

Hi friends

here anybody couldn't solve my problem. anybody couldn't solve my problem what i think.I have sent 4 times reply and see the 1000 time. but anybody couldn't solve my problem. Please tell me the correct way and correct procedure atleast this time.

what i think send error message in my redirect message. Please see my coding. but print always null............

MyAction page coding

if( (admnName.equals(admn)) && (admnPwd.equals(pwd)))

{

return(mapping.findForward("showres"));

}

else

{

request.setAttribute("errMsg","Sorry Mismatch");

return(mapping.findForward("index"));

}

Index.jsp page

<body>

<center>

<%= (String)request.getAttribute("errMsg") %>

<html:errors />

<html:form action="/adminCheck.do">

User Name : <html:text property="userName" />

Password : <html:password property="userPass" />

<html:submit value="Login">

</html:submit>

</html:form>

</center>

</body>

struts-config.xml coding

action-mappings>

<action input="/pages/index.jsp" name="AdminCheckForm"

path="/adminCheck" scope="request" type="Sample.AdminCheckAction">

<forward name="showres" path="/pages/showres.jsp"/>

<forward name="index" path="/pages/index.jsp" redirect="true"/>

</action>

</action-mappings>

If i give wrong username correctly come to index.jsp page. but didn't print (Sorry Mismatch) but alway print null,nulll............................

Please tell me the correct way. please

thanks

pooja

sherin_poojaa at 2007-7-13 20:04:15 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9
I have solved the problem myself. Thank you for all the guys help. Now i am learning in struts .This forum is useful for me. again and again a lot of thanks in this forum.Regardspooja
sherin_poojaa at 2007-7-13 20:04:15 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...