
package com.javaweb.ch15.action;
import com.javaweb.ch14.LoginCheck;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ActionContext;
public class LoginAction3 extends ActionSupport{
private String upassword;
private String uname;
public String getUname(){
return uname;
}
public void setUname(String uname){
this.uname=uname;
}
public String getUpassword(){
return upassword;
}
public void setUpassword(String upassword){
this.upassword=upassword;
}
public void validate(){
if(getUname()==null||"".equals(getUname().trim())){
this.addFieldError("uname","username is required");
}
if(getUpassword()==null||"".equals(getUpassword().trim())){
this.addFieldError("upassword", "password is required");
}
}
public String execute() throws Exception{
LoginCheck lc=new LoginCheck();
if(lc.isLogin(getUname(), getUpassword())){
ActionContext.getContext().getSession().put("login", "true");
return "success";
}else{
return "failure";
}
}
}
其中struts.xml文件的配置代码如下:
"-//Apache Sofeware Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
补充说明:上面省略了login2.jsp代码
login2.jsp能测试成功
按下登录出现如下错误:
HTTP Status 404 - /ODBC/login
type Status report
message /ODBC/login
description The requested resource (/ODBC/login) is not available
Apache Tomcat/5.5.27
Tomcat服务器提示栏console出现如下错误:
警告: Settings: Could not parse struts.locale setting, substituting 警告: No configuration found for the specified action: 'login' in namespace: ''. Form action defaulting to 'action' attribute's literal value.
2009-8-12 16:54:47 org.apache.struts2.components.Form evaluateExtraParamsServletRequest
警告: No configuration found for the specified action: 'login' in namespace: ''. Form action defaulting to 'action' attribute's literal value.
login2.jsp的代码如下:
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%@taglib prefix="s" uri="/struts-tags"%>
用户登录
错误提示:找不到Action
如果你的login.jsp里表单是html标签的话,要写成