<s:textfield label="UserName" name="username" size="40" maxlength="10" />
name是什么作用为什么我把“username”改成别的(例如"usernameaaaa")就是错的我从login界面跳到成功或失败界面(成功失败界面只是单存显示字)就跳...
name是什么作用为什么我把“username”改成别的(例如"usernameaaaa")就是错的
我从login界面跳到成功或失败界面(成功失败界面只是单存显示字)就跳转不了
他是怎么获取文本框里的内容给Java代码进行判断的
Login.jsp界面:
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Login Screen</title>
</head>
<body>
<s:form action="login.action">
<table align="center">
<s:textfield label="UserName" name="username" size="40" maxlength="10" />
<s:textfield label="PassWord" name="password" size="40" maxlength="10" />
<s:submit value="Login" />
</table>
</s:form>
</body>
</html>
LoginAction.java:
package com.hp.action;
public class LoginAction {
private String username;
private String password;
public void setUsername(String username) {
this.username = username;
}
public String getUsername() {
return username;
}
public void setPassword(String password) {
this.password = password;
}
public String getPassword() {
return password;
}
public String enterMethod() {
if (getUsername().equals("scott") && getPassword().equals("tiger")) {
return "success";
} else {
return "error";
}
}
}
strust.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="default" extends="struts-default">
<action name="login" class="com.hp.action.LoginAction" method="enterMethod">
<result name="error">/error.jsp</result>
<result name="success">/success.jsp</result>
</action>
</package>
</struts> 展开
我从login界面跳到成功或失败界面(成功失败界面只是单存显示字)就跳转不了
他是怎么获取文本框里的内容给Java代码进行判断的
Login.jsp界面:
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Login Screen</title>
</head>
<body>
<s:form action="login.action">
<table align="center">
<s:textfield label="UserName" name="username" size="40" maxlength="10" />
<s:textfield label="PassWord" name="password" size="40" maxlength="10" />
<s:submit value="Login" />
</table>
</s:form>
</body>
</html>
LoginAction.java:
package com.hp.action;
public class LoginAction {
private String username;
private String password;
public void setUsername(String username) {
this.username = username;
}
public String getUsername() {
return username;
}
public void setPassword(String password) {
this.password = password;
}
public String getPassword() {
return password;
}
public String enterMethod() {
if (getUsername().equals("scott") && getPassword().equals("tiger")) {
return "success";
} else {
return "error";
}
}
}
strust.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="default" extends="struts-default">
<action name="login" class="com.hp.action.LoginAction" method="enterMethod">
<result name="error">/error.jsp</result>
<result name="success">/success.jsp</result>
</action>
</package>
</struts> 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询