2015-12-25 33 views
1

當我輸入在JSP頁面的用戶名和密碼,該數據就是不能過去到代碼中,我得到了以下錯誤:意外的異常捕獲設置上,錯誤設定表達

意外的異常捕獲設置錯誤設置表達式'password',值爲['123456',]

意外異常捕獲設置類action.login上的'用戶名',錯誤設置表達式'用戶名'與值[''測試',]

的login.jsp:

<body> 
    <s:form action="login" method="post"> 
     <s:textfield label="username" name="username"/> 
     <s:password label="password" name="password"/> 
     <s:submit value="submit"/> 
    </s:form> 
</body> 

這是我的動作類: Login.java

public class Login extends ActionSupport implements ModelDriven<User>, Preparable { 
    /** 
    * 123 
    */ 
    private static final long serialVersionUID = -2484039811971165080L; 
    private IUserService userService=null; 
    private String id; 
    private int pageIndex=1; 
    private String pageBar; 
    private List<User> list_t; 
    private User user; 

    public void prepare()throws Exception{ 
     System.out.println("--prepare--"); 
     System.out.println(id); 
     if(id==null||id.length()==0){ 
      user=new User(); 
     }else{ 
      user=getUserService().getUserById(Integer.parseInt(id)); 
     } 
    } 
    public String execute()throws Exception{ 
     System.out.println("--execute--"); 
     System.out.println(user.getId()); 
     System.out.println(user.getPassword()); 
     if(getUserService().isLogin(user)){ 
      return SUCCESS; 
     } 
     return INPUT; 
    } 
    public String save()throws Exception{ 
     if(getUserService().insertUser(user)){ 
      return SUCCESS; 
     } 
     return ERROR; 
    } 
    public String edit(){ 
     return SUCCESS; 
    } 
    public String update()throws Exception{ 
     if(getUserService().updateUser(user)){ 
      return SUCCESS; 
     } 
     return ERROR; 
    } 
    public String delete()throws Exception{ 
     if(getUserService().deleteUser(Integer.parseInt(id))){ 
      return SUCCESS; 
     } 
     return ERROR; 
    } 
    public String findAllUser()throws Exception{ 
     try { 
      System.out.println("findAllUser"); 
      list_t=getUserService().getAllUser(); 
      ServletActionContext.getRequest().setAttribute("list", list_t); 
     } catch (Exception e) { 
     } 
     return SUCCESS; 
    } 
    public String getId() { 
     return id; 
    } 

    public void setId(String id) { 
     this.id = id; 
    } 

    public int getPageIndex() { 
     return pageIndex; 
    } 

    public void setPageIndex(int pageIndex) { 
     this.pageIndex = pageIndex; 
    } 

    public String getPageBar() { 
     return pageBar; 
    } 

    public void setPageBar(String pageBar) { 
     this.pageBar = pageBar; 
    } 

    public List<User> getList() { 
     return list_t; 
    } 

    public void setList(List<User> list) { 
     this.list_t = list; 
    } 

    public User getUser() { 
     return user; 
    } 

    public void setUser(User user) { 
     this.user = user; 
    } 

    public void setUserService(IUserService userService) { 
     this.userService = userService; 
    } 
    public IUserService getUserService() { 
     return userService; 
    } 
    public User getModel() { 
     // TODO Auto-generated method stub 
     return user; 
    } 

} 
+0

你是什麼意思的「數據不能過去的代碼」? – AdamJeffers

+0

該代碼無法獲得我輸入的'用戶名'和'密碼'。 – Wang

+0

除非你知道你在做什麼,否則不要使用modeldriven。 –

回答

0

快速回答:

的問題是,在你的行動,你不必宣佈字段「密碼」,如:

private String username; //{add getters&setters too} 
private String password; //{add getters&setters too} 

個問候:)

-1

對於場驅動

 溶液如上所述,生成getter & setter方法。   bcuz,屬性有getter和setter方法,var沒有它。  例如:

<form action="/sForm.do" method="post"> 
 
    用戶名: <input type="text" name="username"><br/> 
 
    密&emsp;碼:<input type="password" name="password"><br/> 
 
    <input type="submit"><br/> 
 
</form>

package demo.driven; 
import com.opensymphony.xwork2.ActionSupport; 

public class SForm extends ActionSupport { 
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; 
} 

@Override 
public String execute() throws Exception { 
    System.out.println("username='" + username + "'\'," + "password='" + password + "'"); 
    return SUCCESS; 
} 
} 

對於模型驅動

 只需要實現模型驅動,實例化對象,重寫getModel()例如:

package demo.driven; 

import com.opensymphony.xwork2.ActionSupport; 
import com.opensymphony.xwork2.ModelDriven; 
import demo.model.User; 

public class SForm extends ActionSupport implements ModelDriven<User> { 
private User user = new User(); 

@Override 
public String execute() throws Exception { 
    System.out.println(user); 
    return SUCCESS; 
} 

@Override 
public User getModel() { 
    return user; 
    } 
} 

ps:Class用戶已經包含Getter & setter方法。
我的英文很差,需要用翻譯工具去理解,請原諒我。

+0

這不提供問題的答案。一旦你有足夠的[聲譽](https://stackoverflow.com/help/whats-reputation),你將可以[對任何帖子發表評論](https://stackoverflow.com/help/privileges/comment);相反,[提供不需要提問者澄清的答案](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-c​​an- I-DO-代替)。 - [來自評論](/ review/low-quality-posts/18741908) – Curt

相關問題