2013年9月2日星期一

SSH problem No action instance for path / login could be created

struts-config.xml









type = "com.serlvet.Login"
name = "UserLogin"
parameter = "methode"
scope = "request"
validate = "false">






userLogin.java
package com.serlvet;
import com.model. *;
import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class userLogin extends HttpServlet {

private static final long serialVersionUID = 5698967530097079333L;

public void doGet (HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

response.setContentType ("text / html");
response.setCharacterEncoding ("utf-8");


/ / get the user name and password, verify that the user is legitimate

String username = request.getParameter ("txtloginName");
String userpassword = request.getParameter ("txtpassword");

/ / validate user
Login ubb = new Login ();

try {
if (ubb.checkUser (username, userpassword)) {

/ / User legitimate

/ / user information to successfully log back into session [ used ]

UserBean ub = ubb.getUserBean (username);
request.getSession (). setAttribute ("userInfo", ub);

request.getRequestDispatcher (""). forward (request, response);
} else {

/ / user is not legitimate

request.getRequestDispatcher (""). forward (request, response);
}
} catch (CloneNotSupportedException e) {
/ / TODO Auto-generated catch block
e.printStackTrace ();
}

}

public void doPost (HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

this.doGet (request, response);
}

}
Login.java
package com.model;

import java.sql. *;

import com.model.OpenDB;
import com.model.UserBean;


public class Login {

public String userName;
public String userPassword;
private Connection dbConn;
OpenDB dbconn = new OpenDB ();
Connection con = dbconn.getConnection ();

public Login () {
userName = "";
userPassword = "";
dbConn = null;
}
public boolean checkUser (String u, String p) throws CloneNotSupportedException {


boolean b = false;


try {

Statement ct = null;
ResultSet rs = null;
ct = dbConn.createStatement ();
PreparedStatement ps = null;
/ / top 1 represents found a record is returned , improve query speed
ps = (PreparedStatement) ct.executeQuery ("select top 1 passwd from root where username =?");

ps.setString (1, u);

rs = ps.executeQuery ();

if (rs.next ()) {

/ / remove the database password
String dbPasswd = rs.getString (1);

if (dbPasswd.equals (p)) {

b = true;
}
}
} catch (Exception e) {
e.printStackTrace ();
} finally {

/ / close the resource
this.clone ();
}

return b;

}

public UserBean getUserBean (String u) throws CloneNotSupportedException {

UserBean ub = new UserBean ();
try {

Statement ct = null;
PreparedStatement ps = null;
ResultSet rs = null;
ct = dbConn.createStatement ();
ps = (PreparedStatement) ct.executeQuery ("select top 1 * from root where username =?");
ps.setString (1, u);
rs = ps.executeQuery ();
if (rs.next ()) {

ub.setUserid (rs.getLong (1));
ub.setUsername (rs.getString (2));
ub.setPasswd (rs.getString (3));
}

} catch (Exception e) {
e.printStackTrace ();
/ / TODO: handle exception
} finally {
this.clone ();
}

return ub;
}

public void setConnection (Connection dbConn) {
this.dbConn = dbConn;
}

public void update (String xguserpassword) throws SQLException {
Statement stmt = con.createStatement ();
stmt.executeUpdate ("update root set userPassword = '" + xguserpassword + "' where UserID = '"+ userName +"' ");
}
}
web.xml




action
org.apache.struts.action.ActionServlet

config
/ WEB-INF/struts-config.xml



action
*. do


index.jsp





------ Solution ------------------------------------ --------

com.serlvet.Login this class has it ? ? ? configuration does not know there is no problem , you can see whether you can access other action , make a comparison and then look
------ Solution ------------ --------------------------------
userLogin into this class U serLogin
------ For reference only ------------------- --------------------
No action instance for path / login could be created
The server encountered an internal error (No action instance for path / login could be created) that prevented it from fulfilling this request.

------ For reference only ---------------------------------- -----
well, thank you !

没有评论:

发表评论