小编lee*_*lee的帖子

PortalUtil.getOriginalServletRequest和PortalUtil.getHttpServletRequest有什么区别?

我想知道它们之间的区别

PortalUtil.getOriginalServletRequest(portletRequest) 
Run Code Online (Sandbox Code Playgroud)

PortalUtil.getHttpServletRequest(portletRequest).
Run Code Online (Sandbox Code Playgroud)

java portlet liferay

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

冬眠的工作。每次都要使用交易吗?如果我在重新绑定数据时不使用它,会引起任何问题吗?

我写了下面的代码来从数据库中检索数据,那我们需要开始事务吗?因为它运行没有任何问题。是否有必要每次使用?如果不这样做,将来会不会引起任何问题?

public static Student getStudentById(long id) {
    Session session = null;
    Student student = null;
    //Transaction transaction=null;
    try {
        session = HibernateUtil.getSessionFactory().openSession();
        //transaction = session.getTransaction();
        //transaction.begin();
        /**
         * names in the query should match the related class name and variable names.
         */
        Query query = session.createQuery("from Student where studentId = :id");
        query.setLong("id", id);
        student = (Student) query.uniqueResult();
        //transaction.commit();
    } catch (HibernateException e) {
        //transaction.rollback();
        e.printStackTrace();
    } finally {
        session.close();
    }
    return student;
}
Run Code Online (Sandbox Code Playgroud)

java session hibernate

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

我一直试图通过Liferay中的java Web应用程序发送邮件,但似乎没有用

下面是我的代码,请指出我做错了什么?java我试图通过使用我们的内部网络来做到这一点.这是在MVC portlet中的processAction方法中编写的.

String name=actionRequest.getParameter("name");
String email=actionRequest.getParameter("email");
String myMessage=actionRequest.getParameter("message");

String host = "smtp.xyz.com";
int port = 25;
String username = "xxx";
String password = "yyy";

    Properties props = new Properties();
    props.put("mail.transport.protocol","smtp");
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.host", "smtp.xyz.com");
    props.put("mail.smtp.starttls.enable", "true");
    props.put("mail.smtp.user", username);
    props.put("mail.smtp.password", password);


    Session session = Session.getInstance(props);

    try {

        Message message = new MimeMessage(session);
        message.setFrom(new InternetAddress(email));
                          message.setRecipients(Message.RecipientType.TO,InternetAddress.parse("xxx"));
        message.setSubject("Testing Subject");
        message.setText("From " + name + "," + myMessage);

        Transport transport = session.getTransport("smtp");
        transport.connect(host, port, username, password);

        Transport.send(message);

        System.out.println("Done");

    } catch (MessagingException e) {
        throw …
Run Code Online (Sandbox Code Playgroud)

java liferay

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

标签 统计

java ×3

liferay ×2

hibernate ×1

portlet ×1

session ×1