Category:JSP

  • Example of adding transaction support to JDBC template in spring

    Time:2020-10-27

    Copy codeThe code is as follows: public interface JdbcTemplate extends JdbcOperations {public abstract void beginTranstaion(); public abstract void commit(); public abstract void rollback();} Copy codeThe code is as follows: public class JdbcTemplateImpl extends org.springframework.jdbc.core.JdbcTemplate implements JdbcTemplate {  private PlatformTransactionManager platformTransactionManager; private DefaultTransactionDefinition transactionDefinition; private ThreadLocal<TransactionStatus> transcationStatus = new ThreadLocal<TransactionStatus>();  public void beginTranstaion() {  TransactionStatus tmp = platformTransactionManager.getTransaction(transactionDefinition);  transcationStatus.set(tmp); }  public […]

  • Implementation of java interface example with BeanShell through spring

    Time:2020-10-26

    explain 1. Let Java execute dynamic code through script language2. The script language can be proxy to java interface implementation class with spring3. Spring 2.5.6 supports three scripting languages ruby, groovy and BeanShell4. In the example, spring is combined with BeanShell5. Rely on spring 2.5.6, bsh-2.0b4 Copy codeThe code is as follows: import org.junit.Test;import org.springframework.scripting.bsh.BshScriptUtils; […]

  • Spring dynamic bean registration example sharing

    Time:2020-10-25

    1. In some special scenarios, it is necessary to register beans with spring dynamically2. Spring version 2.5.6 Copy codeThe code is as follows: public class ServiceServiceImpl implements ServiceService, ApplicationContextAware {  @Override public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)   throws BeansException {  this.context = applicationContext; }  public void addBeanService(Service service) throws BVSException {  if (!context.containsBean(service.getServiceName())) {   Class<?> serviceClass = getServiceClass(service.getClassName());   BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.genericBeanDefinition(serviceClass);   beanDefinitionBuilder.addPropertyValue(“servicename”, service.getServiceName());   registerBean(service.getServiceName(), beanDefinitionBuilder.getRawBeanDefinition());  } […]

  • JSP judge the regularity of mobile devices

    Time:2020-10-24

    I saw a good article, “what do you do in the front end of tmall? 》In it, tmall PHP judges the regularity of mobile devices (personal guess), which is very useful, so it decided to transplant it to JSP. JSP file name is index.jsp In fact, you can also use the filter to intercept and […]

  • How to set the absolute path of JSP file

    Time:2020-10-23

    Copy codeThe code is as follows: <% String path = request.getContextPath(); String basePath = request.getScheme() + “://” + request.getServerName() + “:” + request.getServerPort() +Path + “/”; / / return form http://localhost :8080/upload/> Call: Copy codeThe code is as follows: <%=basePath%> It can also be used directly in JS code

  • Examples of mixed use of JSP and SQL statements

    Time:2020-10-22

    If you don’t say much, just give me an exampleinsert Copy codeThe code is as follows: String sql=”insert into allorder values(‘” + orderid + “‘,’” + bookid +”‘,’” + amount + “‘,’” + username + “‘)”; int result=stmt.executeUpdate(sql); if(result==1) response.sendRedirect(“index.jsp”); else response.sendRedirect(“detail.jsp”); delete Copy codeThe code is as follows: String condition=”delete from allorder where id=’”+ […]

  • JSP to get the session from action, clear session and judge

    Time:2020-10-21

    There are several methods for JSP to obtain the session value from action For example, I have a session (“sessionid”, “sessionvalue”) in my action 1、 Use the struts tag to get: < s: property value = “# session.sessionid / > 2、 <%= request.getSession.getAttribute (“sessionid”); > session is also one of the built-in objects request.getSession It’s […]

  • Example of foreach traversal and escape character of JSP simple custom tag

    Time:2020-10-20

    Then yesterday, if the items type in < foreach > is of map or collection type, how to use the enhanced for loop;First, create a tag handler class and define two attributes, string VaR; object items;Because items want to iterate over various sets, object is used;Then the setter method is rewritten;Declaring a member variable of […]

  • The ifelse of JSP custom tag and the example of traversing custom tag

    Time:2020-10-19

    The first example:Simple JSP custom tag to get content:First create a JSP instance class, and then inherit the simpletagsupport classThen implement the dotag () method of the parent classIn this method, we get the content of the tag body this.getJspBody ();Return the jspfragment class, and call invoke according to this class object( this.getJspContext ().getOut());This method […]

  • Effective solution of JSP loading JS file does not work

    Time:2020-10-18

    Directory structure: JSP importing jQuery files always does not work because: Copy codeThe code is as follows: <script type=”text/javascript” src=”js/jquery-1.4.2.min.js”></script> It cannot access the files in the / WEB-INF / directory, so you need to put the loaded JS file into the webapp directory. test.html: Copy codeThe code is as follows: <%@ page language=”java” %> <%@ […]

  • How to center pictures in div in JSP

    Time:2020-10-17

      JSP, let the image in the div center display, as shown in the above figure example: Copy codeThe code is as follows: //CSS file<style type=”text/css”> #bj{ width:200px; height:200px; border:3px solid red; text-align:center; vertical-align:middle; display:table-cell; //Display objects as table cells background:pink; } img{ width:150px; height:150px; margin:0 auto; vertical-align:middle; border:2px solid green; } </style> </head> //Body […]

  • Using JSP to call JavaBean to implement a super simple web calculator example

    Time:2020-10-16

    Here is the code: Calculator.java Copy codeThe code is as follows: package com.amos.model; import java.math.BigDecimal; /** * @ClassName: Calculator *@ Description: Calculator * @author: amosli * @email:[email protected] * @date Mar 20, 2014 1:04:59 AM  */ public class Calculator {     private String firstnum=”0″;     private String secondnum=”0″;     private char operator=’+’;     private String result; […]