2

我正在尝试创建一个自动完成的文本输入。

我听说现在最好使用它,<sj:autocompleter>而不是<sx:autocompleter>因为 dojo 已被弃用但我被卡住了。

我想知道如何在我的 Action 类中调用方法并将其显示在 JSP 上。

我已经看到其他人建议struts.xmljson-default.

我试过了,然后我的课程就不起作用了(因为它是在不同的包中定义的)。

我已经将文件削减到裸露,所以这就是我所拥有的,请帮助:

pom依赖:

<dependencies>
<!--  Struts 2 -->
<dependency>
    <groupId>org.apache.struts</groupId>
    <artifactId>struts2-core</artifactId>
    <version>2.1.8.1</version>
</dependency>

<dependency>
    <groupId>org.apache.struts</groupId>
    <artifactId>struts2-sitemesh-plugin</artifactId>
    <version>2.1.8.1</version>
</dependency>

<dependency>
    <groupId>org.apache.struts</groupId>
    <artifactId>struts2-spring-plugin</artifactId>
    <version>2.1.8.1</version>
</dependency>

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jsp-api</artifactId>
    <version>2.0</version>
    <scope>provided</scope>
</dependency>

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.0.5</version>
</dependency>

<dependency>
    <groupId>org.apache.ibatis</groupId>
    <artifactId>ibatis-sqlmap</artifactId>
    <version>2.3.0</version>
</dependency>

</dependencies>

完整的 application-context.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC 
    "-//SPRING//DTD BEAN//EN" 
    "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>
    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="classpath:jdbc.properties"/>
    </bean>

    <bean id="baseCarsAction" class="com.microed.cars.web.BaseCarsAction" singleton="false" >
            <property name="carsService" ref="carsService"/>
    </bean>

<bean id="homeAction" class="com.microed.cars.web.HomeAction" singleton="false" parent="baseCarsAction" >
    </bean>

    <bean id="carsService" class="com.microed.cars.business.CarsService" singleton="false" >
        <property name="carsDAO" ref="carsDAO"/>
    </bean>

    <bean id="carsDAO" class="com.microed.cars.dataaccess.CarsDAO" singleton="false" />
</beans>

完成 home.jsp(请注意我的评论“我如何在此处获得结果”)

    <!DOCTYPE html PUBLIC 
        "-//W3C//DTD XHTML 1.1 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <%@taglib prefix="s" uri="/struts-tags" %>

    <s:form action="index" >
      <s:url id="loginURL" action="login" />
        <div class="row">
            <div class="span4">
            </div>
        </div>

      <div class="transBlock">
        <div class="row">
            <div class="span7 offset1">
                <s:textfield name="searchTags" cssClass="span7" placeholder="%{getText('placeholder.search.home')}" />      
            </div>

            <div class="span2 offset1" title="<s:text name='tooltip.search.keywords'/>" >
                <s:submit key="button.search" method="searchTags" cssClass="btn btn-success span2" id="btnSearch" />        
            </div>

            <!--  after calling getData in action class - how do I display it here? -->
        </div>

      </div>
    </s:form>

完成 HomeAction:

package com.microed.cars.web;

import java.sql.SQLException;

public class HomeAction extends BaseCarsAction {
    /** How do I call this when user inputs into a text field? **/
    public void getData() throws SQLException {
    }

    @Override
    public String execute() throws Exception {
        return INPUT;
    }

}

注入服务的基本动作类:

package com.microed.cars.web;

import org.springframework.beans.factory.annotation.Required;

import com.microed.cars.business.CarsService;
import com.opensymphony.xwork2.ActionSupport;

public class BaseCarsAction extends ActionSupport {

    protected CarsService carsService;
    protected String searchTags;

    @Required
    public void setCarsService(CarsService carsService) {
        this.carsService = carsService;
    }

}
4

0 回答 0