Results 1 to 8 of 8
- 04-20-2009, 10:37 AM #1
Member
- Join Date
- Mar 2009
- Posts
- 14
- Rep Power
- 0
No action instance for path /login could be created
Hello!
I am a new user of Struts , when i click the submit button , following error message is received :
No action instance for path /login could be created
Following is the code of struts-config.xml file
<struts-config>
<form-beans type="org.apache.struts.action.ActionFormBean">
<form-bean name="LoginForm" type="net.form.LoginForm" />
</form-beans>
<global-exceptions>
</global-exceptions>
<global-forwards></global-forwards>
<action-mappings>
<action path="/login" name="LoginForm" validate="false" input="/index.jsp"
type="net.LoginAction">
<forward name="success" path="/Welcome.jsp" />
<forward name="failure" path="/index.jsp" />
</action>
</action-mappings>
<message-resources parameter="resource.MessageResource"></message-resources>
</struts-config>
and following is the code of index.jsp file
<html:form action="login">
<html:text property="userName"></html:text>
<html:errors property="userName" />
<br/>
<html:password property="password"></html:password>
<html:errors property="password"/>
<html:submit/>
<html:reset/>
</html:form>
</body>
</html>
can anyone plz hel me out...
Thanks in advance
Nida
- 04-20-2009, 11:14 AM #2
Have you checked the action class is residing in the folder what u specified? Check the folder struture once
- 04-20-2009, 12:17 PM #3
Member
- Join Date
- Mar 2009
- Posts
- 14
- Rep Power
- 0
The path of action class (instruts-config.xml ), was not correct ,..i have corrected that but now it is not redirecting to desired page Welcome.jsp...
Thaaaaanx alot for ur support
- 04-20-2009, 12:48 PM #4
Member
- Join Date
- Mar 2009
- Posts
- 14
- Rep Power
- 0
i am facing another problem ...records are not inserted in data base , while i recvd the message of insertion..
Following is the code of Action class
package net.action;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.form.LoginForm;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import DB.DB;
public class LoginAction extends Action {
public ActionForward execute(ActionMapping mapping,ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
//DB d= new DB();
String target = null;
String name;
String pass;
LoginForm loginForm = (LoginForm)form;//new LoginForm();
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";
String db = "teralight";
String driver = "com.mysql.jdbc.Driver";
if(loginForm.getUserName()!=null && loginForm.getPassword()!=null)
{
target = "success";
request.setAttribute("message", loginForm.getPassword());
name=loginForm.getUserName();
pass=loginForm.getPassword();
StringBuffer sbQuery = new StringBuffer("");
System.out.println("name is"+name);
System.out.println("Connectig database !!!");
try{
Class.forName(driver);
con = DriverManager.getConnection(url+db,"root","root");
try{
Statement st = con.createStatement();
System.out.println("111111 !!!");
// int val = st.executeUpdate("INSERT into usrs VALUES("+"name,"+"pass'"+")");
sbQuery.append("INSERT INTO usrs(Name,Password) VALUES('");
sbQuery.append(name + "','");
sbQuery.append(pass + "')");
System.out.println("1 row affected");
}
catch (SQLException s){
System.out.println("SQL statement is not executed!");
}
con.close();
}
catch (Exception e){
e.printStackTrace();
}
}
else {
target = "failure";
}
return mapping.findForward(target);
}
}
- 04-20-2009, 12:58 PM #5
One small suggestion.If u want to send some dynamically use preparedstatement instead of statement class.It will not create problem.
Just change the statement part and include this
PreparedStatement ps = con.prepareStatement("INSERT INTO USRS VALUES(?,?)");
ps.setString(1,name);
ps.setString(2,pass);
int updateCount = ps.executeUpdate();
System.out.println("Update Count "+ updateCount);
Try the above chunk of code and tellme if there are any problems
- 04-20-2009, 01:25 PM #6
Member
- Join Date
- Mar 2009
- Posts
- 14
- Rep Power
- 0
I got a type mismatch error in line
con.prepareStatement("INSERT INTO USRS VALUES(?,?)");
how to resolve it ,..if i type cast it then database is not connected..
Help me out
- 04-20-2009, 01:35 PM #7
IN usrs table are u having only 2 String fields? Just check whether u are having only 2 fields in usrs table.
This typemismatch error comes if u are trying to set the value which is not having expected datatype or expected column.
Try this
con.prepareStatement("INSERT INTO USRS(name,password)VALUES(?,?)");
ps.setString(1,name);
ps.setString(2,pass);
int updateCount = ps.executeUpdate();
- 04-21-2009, 06:00 AM #8
Member
- Join Date
- Mar 2009
- Posts
- 14
- Rep Power
- 0
Similar Threads
-
Vector getting re-created with each call
By nidhirastogi in forum Advanced JavaReplies: 6Last Post: 10-17-2008, 07:37 AM -
cannot open database requested in login. Login fails
By banduskank in forum JDBCReplies: 0Last Post: 06-25-2008, 12:41 PM -
Exception Report:annot allocate servlet instance for path
By mary in forum Java ServletReplies: 4Last Post: 11-05-2007, 05:14 PM -
Help, created a username and password box
By cachi in forum AWT / SwingReplies: 1Last Post: 08-07-2007, 04:21 AM -
create a tree when a new class is created
By osval in forum Advanced JavaReplies: 1Last Post: 08-06-2007, 08:58 PM


LinkBack URL
About LinkBacks

Bookmarks