loginAction和loginForm代码: package com.measinfo.struts.action; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import javax.sql.*; import java.sql.*; 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 com.measinfo.struts.form.LoginForm; public class LoginValAction extends Action { public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { LoginForm loginForm = (LoginForm) form;// TODO Auto-generated method stub // String username =loginForm.getUsername(); String username =request.getParameter("username"); String password =loginForm.getPassword(); System.out.println(username); System.out.println(password); try { Connection con =this.getDataSource(request,"keyOne").getConnection(); Statement st =con.createStatement(); String sql="select password from person where name='"+username+"'"; ResultSet rs =st.executeQuery(sql); System.out.println(sql); if(rs.next()){ if(rs.getString(1).equals(password)){ response.getWriter().print("true"); return null; }else{ response.getWriter().print("false"); return null; } } return null; } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); return mapping.findForward("no"); } } } loginForm代码: /* * Generated by MyEclipse Struts * Template path: templates/java/JavaClass.vtl */ package com.measinfo.struts.form; import javax.servlet.http.HttpServletRequest; import org.apache.struts.action.ActionErrors; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionMapping; /** * MyEclipse Struts * Creation date: 07-28-2010 * * XDoclet definition: * @struts.form name="loginForm" */ public class LoginForm extends ActionForm { /* * Generated fields */ /** userName property */ private String username; /** password property */ private String password; /* * Generated Methods */ /** * Method validate * @param mapping * @param request * @return ActionErrors */ public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { // TODO Auto-generated method stub return null; } /** * Method reset * @param mapping * @param request */ public void reset(ActionMapping mapping, HttpServletRequest request) { // TODO Auto-generated method stub } /** * Returns the userName. * @return String */ public String getUsername() { return username; } /** * Set the userName. * @param userName The userName to set */ public void setUsername(String userName) { System.out.println(userName+".................."); this.username = userName; } /** * Returns the password. * @return String */ public String getPassword() { return password; } /** * Set the password. * @param password The password to set */ public void setPassword(String password) { this.password = password; } }