配置文件<!-- ========== Action Mapping Definitions ============================== -->
<action-mappings>
<action path="/search"
type="addressbook.actions.SearchAction"
name="searchForm"
attribute="myForm"
scope="request"
input="/search.jsp">
<forward name="success" path="/display.jsp"/>
</action>但是我沒有看到執行strSql 數據庫代碼??
請看下面的語句?
----SearchAction 所有代碼
public final class SearchAction extends AbstActionBase { private Log log =
LogFactory.getLog(this.getClass().getName()); public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception { Locale locale = getLocale(request);
MessageResources messages = getResources(request); ActionMessages errors = new ActionMessages();
String name = ((SearchForm) form).getName();
String phone = ((SearchForm) form).getPhone();
String address=((SearchForm)form).getAddress(); if (!errors.isEmpty()) {
saveErrors(request, errors);
return (new ActionForward(mapping.getInput()));
} String strSql = new String("SELECT * FROM " + Constants.TABLENAME + " WHERE "); if (!name.equals(""))
strSql = strSql + "name LIKE '"+ name +"%' AND";
if (!phone.equals(""))
strSql = strSql + " phone LIKE '"+ phone +"%' AND";
if (!address.equals(""))
strSql = strSql + " address LIKE '"+ address +"%'";
else
strSql = strSql.substring(0,strSql.length()-3); strSql = strSql + "ORDER by ID";
HttpSession session = request.getSession();
if (log.isDebugEnabled()) {
log.debug("SearchAction session = " + session);
log.debug("SearchAction strSql = " + strSql); }
session.setAttribute(Constants.SQLSTMT_KEY, strSql); return (mapping.findForward(Constants.FORWARD_SUCCESS)); }
}
<action-mappings>
<action path="/search"
type="addressbook.actions.SearchAction"
name="searchForm"
attribute="myForm"
scope="request"
input="/search.jsp">
<forward name="success" path="/display.jsp"/>
</action>但是我沒有看到執行strSql 數據庫代碼??
請看下面的語句?
----SearchAction 所有代碼
public final class SearchAction extends AbstActionBase { private Log log =
LogFactory.getLog(this.getClass().getName()); public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception { Locale locale = getLocale(request);
MessageResources messages = getResources(request); ActionMessages errors = new ActionMessages();
String name = ((SearchForm) form).getName();
String phone = ((SearchForm) form).getPhone();
String address=((SearchForm)form).getAddress(); if (!errors.isEmpty()) {
saveErrors(request, errors);
return (new ActionForward(mapping.getInput()));
} String strSql = new String("SELECT * FROM " + Constants.TABLENAME + " WHERE "); if (!name.equals(""))
strSql = strSql + "name LIKE '"+ name +"%' AND";
if (!phone.equals(""))
strSql = strSql + " phone LIKE '"+ phone +"%' AND";
if (!address.equals(""))
strSql = strSql + " address LIKE '"+ address +"%'";
else
strSql = strSql.substring(0,strSql.length()-3); strSql = strSql + "ORDER by ID";
HttpSession session = request.getSession();
if (log.isDebugEnabled()) {
log.debug("SearchAction session = " + session);
log.debug("SearchAction strSql = " + strSql); }
session.setAttribute(Constants.SQLSTMT_KEY, strSql); return (mapping.findForward(Constants.FORWARD_SUCCESS)); }
}
解决方案 »
- switch(整形表达式)中的整形表达式为什么不能是long型?
- 如果类中直接带 static 与 构造方法有什么不同?
- JTable如何更新数据和翻页查询
- 疑惑!!!
- 从来没有用过中文为包名的,今天测试在类中取得当前文件所在的相对路径与绝对路径时发现个这个问题,特此提醒一下,有谁设置包名为中文的
- 问一个非常菜的问题,Java程序的运行效率与VB60相比,哪一个更高?用Java开发MIS系统合适吗?JAVA有前途吗?
- 求教菜单事件!!!
- 求助:算24点问题。
- 为什么这个解压缩没有解压后的文件生成
- 请问null指的是什么?什么时候要用到呢?和数据库里的那个null一样意思吗?
- 谁能将我这段代码改成没错误的啊
- Java线程中代码顺序的问题
type="addressbook.actions.SearchAction"
name="searchForm"
attribute="myForm"
scope="request"
input="/search.jsp">
<forward name="success" path="/display.jsp"/>
</action>可以看到 最后轉到display.jsp"