刚开始学struts 2 ,请教高手,怎么接收jsp表单中传递的数据
action类为
package com.leeyas.Login;import com.opensymphony.xwork2.ActionContext;public class loginAction {
private String username;
private String password;
public String getUsername(){
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String execute()throws Exception{
String username = (String)ActionContext.getContext().getSession().get("username");
if("leeyas"==username){
return "success";
}
else{
return "error";
}
}
}
不管前端输入什么,都会跳转到error.jsp,在线等
action类为
package com.leeyas.Login;import com.opensymphony.xwork2.ActionContext;public class loginAction {
private String username;
private String password;
public String getUsername(){
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String execute()throws Exception{
String username = (String)ActionContext.getContext().getSession().get("username");
if("leeyas"==username){
return "success";
}
else{
return "error";
}
}
}
不管前端输入什么,都会跳转到error.jsp,在线等
解决方案 »
- 遇到一个很坑爹的事!!求解
- 谁能给点思路?关于JS脚本问题
- 调试程序时,老是出现这错!
- 请求,新闻发布插入内容问题.....
- 哪位高手告诉我:在使用tomcat连接池的情况下,怎样将普通的resultset转换为oracle.jdbc.OracleResultSet,涉及倒blob字段!!!!
- 新用没分,过后补上.页面href.jsp编码GBK,一个连接中参数带中文,请求页面编码GBK,TOMCAT URIEncoding="UTF-8"请求页面乱码
- jsp 中调用JNI的问题???请大家务必帮忙啊,(分不够在加)
- 关于Servlet的问题
- SoS 从jsp页面读取txt文件出错!!!!???
- 请教如何传递Int类型的变量?
- JSP什么时候才能成为主流
- 网站访问局域网速度很块,外网非常慢,小弟万分感谢!!!
String username = (String)ActionContext.getContext().getSession().get("username");
这个是多余的
<?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="strutsqs" extends="struts-default">
<action name="login" class="com.leeyas.Login.loginAction">
<result name="success">/success.jsp</result>
<result name="error">/error.jsp</result>
</action>
</package>
</struts>login.jsp<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><!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>Insert title here</title>
</head>
<body>
<!--
<s:form action="login.action">
<s:textfield name="username" label="用户名:"/>
<s:textfield name="password" label="密码:"/>
<s:submit name="登陆"/>
</s:form>
-->
<form action="login.action" method = "post">
<input type="text" name="username"><br>
<input type="text" name="password"><br>
<input type="submit" name="登录">
</form>
</body>
</html>
这个确实多余execute方法中直接if("leeyas".equals(username)){ return "success";
}
else{ return "error";
} } }
用以下方式进行判断
if("leeyas".equals(username)) {
return "success";
} else{
return "error";
}