小编J88*_*888的帖子

如何将对象从前端传递给Struts2?

我试图通过JavaScript向Struts2后端发送一个字段的值,但它返回NullpointerException.

<input type="hidden" id="employee.payslip.id" name="employee.payslip.id" value="5"/>
....
Run Code Online (Sandbox Code Playgroud)

提交表单后,请求将被发送到以下JavaScript方法以发送到后端.

 function payslipPayment(){

     var formValues = $('#myform').serialize();
     ....
     xmlhttp.open("get","../payslip/pay?"+formValues,false);
     xmlhttp.send();

 }
Run Code Online (Sandbox Code Playgroud)

请求将被创建并发送如下

http://localhost/payslip/pay/employee.payslip.id=5&employee.payslip.year=2013&....
Run Code Online (Sandbox Code Playgroud)

但在后端,当我试图显示它返回的值NullPointerException.

Java的

public class payslip {

 private Employee employee;

 public String pay{
    System.out.println("Id:"+employee.payslip.id):
    System.out.println("Year:"+employee.payslip.year;
    ...
 }

 getter and setter 

}
Run Code Online (Sandbox Code Playgroud)

类

public class Employee {
   private Payslip payslip;
   ....
   getter and setter
}

public class Payslip{
  private long id;
  ...
  getter and setter
}
Run Code Online (Sandbox Code Playgroud)

javascript java ajax jquery struts2

5
推荐指数
1
解决办法
5382
查看次数

为什么我的二级缓存实现会出错?

我试图在我的应用程序上实现二级缓存,但它返回以下错误.我对setCacheMode很怀疑.

的hibernate.cfg.xml

 ...
  <property name="cache.provider_class">
            org.hibernate.cache.EhCacheProvider
  </property>

  <property name="hibernate.cache.use_query_cache">true</property>
 ...
Run Code Online (Sandbox Code Playgroud)

Product.Java

public class Product implements Serializable {
...
    @Id
    @GeneratedValue
    @Column(name = "id")
    @Cache(usage= CacheConcurrencyStrategy.READ_ONLY)
    public long getID() {
        return ID;
    }
...
}
Run Code Online (Sandbox Code Playgroud)

Model.Java

....
final Session session = HibernateUtil.getSession();
        try {
            final Transaction tx = session.beginTransaction();
            try {
                Product product = (Product) session.get(Product.class, id);
                session.setCacheMode(CacheMode.NORMAL);
                tx.commit();
                return product;
            } catch (Exception e) {
                tx.rollback();
                e.printStackTrace();
            }
        } finally {
            HibernateUtil.closeSession();
        }
.....
Run Code Online (Sandbox Code Playgroud)

错误

INFO: ** Exception in SessionFactory …
Run Code Online (Sandbox Code Playgroud)

java hibernate

5
推荐指数
1
解决办法
8697
查看次数

交易未成功启动(而tx.commit()被if条件包围)

第一次遇到这个错误我用t条件包围了我的tx.commit(),但不知道为什么我仍然收到这个错误.

Struts Problem Report

Struts has detected an unhandled exception:
Messages:   
Transaction not successfully started
File:   org/hibernate/engine/transaction/spi/AbstractTransactionImpl.java
Line number:    200
Stacktraces
org.hibernate.TransactionException: Transaction not successfully started

    org.hibernate.engine.transaction.spi.AbstractTransactionImpl.rollback(AbstractTransactionImpl.java:200)
Run Code Online (Sandbox Code Playgroud)

用户选择产品后,在我的主要功能中,我将调用以下两个功能.

第一个检索所选产品对象的函数.第二个函数检查所选用户是否有产品,因此如果客户有产品则返回true,否则返回false;

功能1

  ....

    Product pro = new Product();
    final Session session = HibernateUtil.getSession();
    try {
        final Transaction tx = session.beginTransaction();
        try {

            pro = (Product) session.get(Product.class, id);

            if (!tx.wasCommitted()) {    
                     tx.commit();
            }
        } catch (Exception e) {
            tx.rollback();
            e.printStackTrace();
        }
    } finally {
        HibernateUtil.closeSession();
    }
   .....
Run Code Online (Sandbox Code Playgroud)

功能2

 .....
 final Session session = …
Run Code Online (Sandbox Code Playgroud)

java hibernate

5
推荐指数
1
解决办法
7713
查看次数

JAXB unmarshalling返回'URI不是绝对'错误

我从webservice收到以下响应,并使用以下代码来解组​​响应,但它返回以下错误.

SEVERE:   java.lang.IllegalArgumentException: URI is not absolute
Run Code Online (Sandbox Code Playgroud)

响应

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org  
                  /2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
        <SearchFlightsResponse xmlns="ElsyArres.API">
            <SoapMessage>
                <Username>TEST</Username>
                <Password>TESTs</Password>
                <LanguageCode>EN</LanguageCode>
                <ErrorMessage />
                <ErrorCode>0</ErrorCode>
                <AppVersion>8.0.3</AppVersion>
                <Request>
                    <Departure>FDH</Departure>
                    <Destination>HAM</Destination>
                    <DepartureDate>2014-08-08</DepartureDate>
                    <ReturnDate />
                    <NumADT>1</NumADT>
                    <NumINF>0</NumINF>
                    <NumCHD>0</NumCHD>
                    <CurrencyCode>EUR</CurrencyCode>
                    <CarrierList />
                    <FareClasses />
                    <Providers />
                    <WaitForResult>true</WaitForResult>
                    <NearbyDepartures>true</NearbyDepartures>
                    <NearbyDestinations>true</NearbyDestinations>
                    <RROnly>false</RROnly>
                    <MetaSearch>true</MetaSearch>
                </Request>
                <Response>
                    <SearchFlightId>140514114543-02-43064-52</SearchFlightId>
                    <Roundtrip>false</Roundtrip>
                    <CurrencyCode>EUR</CurrencyCode>
                    <Flights>
                        <Flight>
                            <Outbound>
                                <CarName>Inter Sky</CarName>
                                <CarCode>3L</CarCode>
                                <DepName>Friedrichshafen</DepName>
                                <DepCode>FDH</DepCode>
                                <DestName>Hamburg</DestName>
                                <DestCode>HAM</DestCode>
                                <Duration>01:45</Duration>
                                <FlightNo>3L370</FlightNo>
                                <DepDateTime>2014-08-08T06:10:00</DepDateTime>
                                <ArrDateTime>2014-08-08T07:55:00</ArrDateTime>
                                <Legs>
                                    <Leg>
                                        <Sequence>0</Sequence>
                                        <FlightNo>3L370</FlightNo>
                                        <DepCode>FDH</DepCode>
                                        <DepName>Friedrichshafen</DepName>
                                        <DestCode>HAM</DestCode>
                                        <DestName>Hamburg</DestName>
                                        <DepTime>06:10</DepTime>
                                        <ArrTime>07:55</ArrTime>
                                        <CarCode>3L</CarCode>
                                        <CarName>Inter Sky</CarName> …
Run Code Online (Sandbox Code Playgroud)

java xml web-services jaxb unmarshalling

5
推荐指数
1
解决办法
2672
查看次数

如何使用 Hibernate 检索类的成员对象?

使用以下代码,我可以成功检索用户的地址字段,为此我需要使用 Projection 定义其所有字段。想象一下 address 有 100 个字段,在这种情况下,我必须定义所有字段。

我想知道是否可以只返回客户的地址对象而无需在 Proposition 中定义其所有字段?

我知道我可以检索地址的 id 并使用它来检索它的对象,但我想知道是否还有其他方法而不是这个方法或定义它的所有字段。

休眠

            .....
            Criteria cre = session.createCriteria(User.class, "user")
                    .createAlias("user.address", "addr");

            cre.add(Restrictions.eq("user.id", ID));

            ProjectionList pl = Projections.projectionList();
            pl.add(Projections.property("addr.id").as("id"));
            pl.add(Projections.property("addr.unit").as("unit"));
            .......
            cre.setProjection(pl);
            Address address = (Address) cre.list().get(0);
Run Code Online (Sandbox Code Playgroud)

我也使用了以下内容,但遇到了错误(无法解析属性:com.myProject.User 的地址)

    pl.add(Projections.property("addr").as("address"));
Run Code Online (Sandbox Code Playgroud)

爪哇

@Entity
public Class User {

     @Id
     @GeneratedValue
     private long id;

     @OneToOne
     private Address address;

     ...
}
Run Code Online (Sandbox Code Playgroud)

java hibernate hibernate-mapping

3
推荐指数
1
解决办法
1710
查看次数

javax.net.ssl.SSLHandshakeException:sun.security.validator.ValidatorException

以前,我可以成功地向Web服务发送请求并接收响应,但它现在返回以下异常.基于其他答案,我需要更新证书,但我需要知道为什么我现在收到此例外.另一个问题是,我可以找到我的java_home的地址,但我无法续订证书.

例外:

javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path validation failed: java.security.cert.CertPathValidatorException: timestamp check failed
Run Code Online (Sandbox Code Playgroud)

码

URI uri = new URI("https", "xml.example.com", "/service/ServiceRequest.do", 
                           "serverName=www.example.com&xml=" 
                           ...
                           +" ", null);

            URL page = uri.toURL();
            HttpsURLConnection conn = (HttpsURLConnection) page.openConnection();
            conn.setRequestMethod("POST");
            conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            conn.setDoOutput(true);
            conn.setDoInput(true);
            conn.connect();
Run Code Online (Sandbox Code Playgroud)

java ssl webservice-client

3
推荐指数
1
解决办法
1万
查看次数

无法解组SOAP响应

我可以发送请求并收到响应,但我无法解析响应.它返回以下错误:

Local Name:Body
error is here
java.lang.NullPointerException
    at com.ticketmaster.ticketmaster.TicketMaster.Search(TicketMaster.java:119)
    at com.ticketmaster.ticketmaster.App.main(App.java:12)
Run Code Online (Sandbox Code Playgroud)

码

    SOAPMessage response
            = connection.call(message, endpoint);

    connection.close();
        SOAPMessage sm = response;
        SOAPBody sb = response.getSOAPBody();
        System.err.println("Node Name:" + sb.getNodeName());  //return nothing
        System.err.println("Local Name:" + sb.getLocalName());  //return Local Name:Body

        DOMSource source = new DOMSource(sb);
        results = (FindEventsResponse) JAXB.unmarshal(source, FindEventsResponse.class);
        System.err.println("Results size: " + this.results.returnTag.results.item.get(0).getName());

} catch (Exception ex) {
    System.err.println("error is here");
    ex.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)

响应:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
                   xmlns:ns1="http://ticketmaster.productserve.com/v2/soap.php" 
                   xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                   xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" 
                   SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    <SOAP-ENV:Body>
        <ns1:findEventsResponse>
            <return xsi:type="ns1:Response">
                <details …
Run Code Online (Sandbox Code Playgroud)

java soap jaxb unmarshalling stringreader

3
推荐指数
1
解决办法
9174
查看次数

为什么<a>标签的href会附加到我当前的地址?

我有一个简单的标签,其中有一个url作为其href,当我点击它时,它会将URL附加到当前地址.

地址是www.example.com/event/

<a href="www.yahoo.com" taget="_blank">Here</a>
Run Code Online (Sandbox Code Playgroud)

当我点击它时,它将变为以下

 www.example.com/event/www.yahoo.com
Run Code Online (Sandbox Code Playgroud)

html action struts2

1
推荐指数
1
解决办法
529
查看次数