求教一个Struts2中execute()方法根据不同的返回值跳转到不同页面的问题??
packagetutorial;importjava.sql.Connection;importjava.sql.ResultSet;importjava.sql.Sta...
package tutorial;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import com.opensymphony.xwork2.ActionSupport;
public class userinfo extends ActionSupport{
private String name;
private String password;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String execute(){
try{
Connection con = new connection().getConnection() ;
Statement stmt=con.createStatement();
String sql = "select * from userinfo where name = '" + name + "' and pwd = '" + password + "'";
ResultSet rs=stmt.executeQuery(sql);
if(rs.next()){
return SUCCESS;
}else{
return ERROR;
}
}catch(Exception e){
}
return SUCCESS;
}
}
<?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="tutorial" extends="struts-default">
<action name="userinfo" class="tutorial.userinfo">
<result name="SUCCESS">/welcome.jsp</result>
<result name="ERROR">/err.jsp</result>
</action>
</package>
</struts>
这是一个简单的登录界面,想根据登录是否成功返回不同的值,跳转到不同的界面,可是却一直报错 展开
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import com.opensymphony.xwork2.ActionSupport;
public class userinfo extends ActionSupport{
private String name;
private String password;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String execute(){
try{
Connection con = new connection().getConnection() ;
Statement stmt=con.createStatement();
String sql = "select * from userinfo where name = '" + name + "' and pwd = '" + password + "'";
ResultSet rs=stmt.executeQuery(sql);
if(rs.next()){
return SUCCESS;
}else{
return ERROR;
}
}catch(Exception e){
}
return SUCCESS;
}
}
<?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="tutorial" extends="struts-default">
<action name="userinfo" class="tutorial.userinfo">
<result name="SUCCESS">/welcome.jsp</result>
<result name="ERROR">/err.jsp</result>
</action>
</package>
</struts>
这是一个简单的登录界面,想根据登录是否成功返回不同的值,跳转到不同的界面,可是却一直报错 展开
2015-03-25
展开全部
将return SUCCESS改为"SUCCESS"
没用字符串而是用的父类的变量SUCCESS,它的值是小写的"success"
没用字符串而是用的父类的变量SUCCESS,它的值是小写的"success"
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询