标签: spring-mvc

无法在textarea上禁用enter键

嗨伙计们,我试图禁止输入密钥在textarea中提交表单

使用以下功能:

function noenter() {
    return !(window.event && window.event.keyCode == 13); 
    }
Run Code Online (Sandbox Code Playgroud)

HTML代码:

<form:form modelAttribute="myObject" method="post" action="${myUrl}">
 <form:textarea path="name" class="new_obj submits_on_return" cols="40" rows="3"  onkeypress="return noenter()"></form:textarea>
Run Code Online (Sandbox Code Playgroud)

但它根本不起作用,总是提交,任何想法为什么?

javascript forms spring-mvc java-ee

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

为什么我应该使用Flex而不是JQuery?

我正在使用Spring的webapp工作,我总是使用JSP和Jquery.在最近的一次谈话中,有人评论道:你应该使用Flex代替.Flex会成为Web应用程序的不错选择吗?使用它与仅使用JSP和Jquery有什么好处?

apache-flex jsp web-applications spring-mvc

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

如何从HTML字符串创建Spring ModelAndView?

我正在从控制器中获取外部网页(作为字符串)。如何将包含HTML的字符串作为返回ModelAndView

spring spring-mvc

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

netbeans 中的 spring 示例应用程序

这是我的代码。我得到了一些错误。谁能帮我解决问题?我收到了一些转换错误,比如ClassPathResource转换到资源Resource和资源对象r到资源。

package firstspring;

import javax.annotation.Resource;

import org.springframework.beans.factory.BeanFactory;

import org.springframework.beans.factory.xml.XmlBeanFactory;

import org.springframework.core.io.ClassPathResource;

import org.springframework.core.io.Resource;

public class test {

public static void main(String[] args){

Resource r =new ClassPathResource("applicationContext.xml");


BeanFactory bf=new XmlBeanFactory(r);

Student stud=(Student)bf.getBean("first");

stud.display();

} 

}
Run Code Online (Sandbox Code Playgroud)

这是我的 XML 文件;

<?xml version="1.0" encoding="UTF-8"?>

<beans 

xmlns="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

 xmlns:p="http://www.springframework.org/schema/p"

 xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

<bean id="first" class="Student">

<property name="name" value="sneha"></property>    

</bean>

</beans>
Run Code Online (Sandbox Code Playgroud)

java spring netbeans spring-mvc

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

如何处理 EntityManger 通过 Spring 应用程序建立的连接池大小

我们有一个Web应用程序中实现Spring MVC 3.2使用JPA作为ORM框架。现在的问题是EntityManager正在创建与数据库的大量开放连接。我们希望以这样一种方式处理它:对于每个查询,都应该在完成后建立和关闭连接。

根据 spring 实现 EntityManager 创建一次。但这里的问题是我们希望以某种方式处理 EntityManager 为查询数据库而创建的客户端连接。

每当在数据库中完成查询时,该连接就会进入睡眠状态,相反,我们希望在查询返回结果后关闭它。

数据库类型: MySQL

我的 JPA 配置是:

<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />

<bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="packagesToScan" value="com.reppify" />
    <property name="jpaPropertyMap" ref="jpaPropertyMap" />
    <property name="dataSource" ref="dataSourceLocal" />
    <property name="persistenceUnitName" value="cron-jpa" />
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
    </property>
</bean>

<bean id="dataSourceLocal"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="${database.driver}" />
    <property name="url" value="${database.url}" />
    <property name="username" value="${database.user}" />
    <property name="password" value="${database.password}" …
Run Code Online (Sandbox Code Playgroud)

java spring jpa spring-mvc

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

Jackson 将 POST 参数映射到 Java POJO

我正在编写一个 Spring RESTful 服务,它使用 JSON 并执行一些操作。由于请求包含大量参数,我想到了使用 Spring 的 Jackson 映射将我的请求参数映射到 Java 对象。

我的POJO

public class RequestInput {

 private int id;
 private String name;
 // parameters follow


 // getter and setter
}
Run Code Online (Sandbox Code Playgroud)

我的控制器

@Controller
public class RequestController{

   @RequestMapping(method=RequestMethod.POST, value="/rest/postRequest")
   public void handleRequest(@RequestBody RequestInput input){
          // code follows
   }

}
Run Code Online (Sandbox Code Playgroud)

数据发布时一切正常

{“id”:1,“名称”:“ABCD”}

但是当数据发布为

{“id”:1,“first_name”:“ABCD”}

对象中名称的值作为 返回NULL

你能帮我理解如何将请求中的 first_name 映射到 Java POJO 中的 name param

rest spring json spring-mvc jackson

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

@RequestParam和@RequestMapping之间的差异

线路1:

public ModelAndView viewCustomerDetails(@RequestParam("custId") Integer customerId, @RequestParam("categoryName") String categoryName, HttpServletRequest request) throws BusinessException{
Run Code Online (Sandbox Code Playgroud)

线路2:

public ModelAndView viewCustomerDetails(@RequestMapping("custId") Integer customerId, @RequestMapping("categoryName") String categoryName, HttpServletRequest request) throws BusinessException{
Run Code Online (Sandbox Code Playgroud)

我要去深入我的项目代码,并具有一定的混乱@RequestParam@RequestMapping一些时间,我发现@RequestParam有的时候@RequestMapping.在我的理解中,两者都将分配custIdcustomerId数据成员的值.

我的jsp文件的一部分:

<form:input mandatory="true" id="CustNameTxt" path="custName" cssClass="txtfield controlWidth" readonly="false" />
Run Code Online (Sandbox Code Playgroud)

为了更好地理解我的问题,我已经在Line2中进行了编辑

java spring spring-mvc request-mapping

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

自动发布的问题/找不到bean

我正在尝试实现Spring Boot并设置我的用户服务.我无法找到无法找到UserService bean的错误.任何建议或方向将不胜感激.

UserController的

@RestController
public class UserController {

    private final IUserService userService;

    @Inject
    public UserController(final IUserService userService) {
        this.userService = userService;
    }

    @RequestMapping(value = "/user", method = RequestMethod.POST)
    public FBUser createUser(@RequestBody @Valid final FBUser fBUser) {
        return userService.save(fBUser);
    }
}
Run Code Online (Sandbox Code Playgroud)

IUserService

public interface IUserService {

    FBUser save(FBUser fBUser);
}
Run Code Online (Sandbox Code Playgroud)

UserService

public class UserService implements IUserService {

    private final IUserRepository repository;

    @Inject
    public UserService(final IUserRepository repository) {
         this.repository = repository;
    }

    @Override
    @Transactional
    public FBUser save(final FBUser fBUser) {
        return …
Run Code Online (Sandbox Code Playgroud)

java spring spring-mvc spring-security spring-boot

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

Spring mvc url参数

我无法展示可能的餐厅.我得到了我的控制器类:

@Controller
public class RestaurantController extends MultiActionController{

    private RestaurantDAO restaurantDAO;

    public void setRestaurantDAO(RestaurantDAO restaurantDAO) {
        this.restaurantDAO = restaurantDAO;
    }


    @RequestMapping("/restaurant/{restaurantId}")
    public ModelAndView restaurantid(@PathVariable("contactId") int id, 
         HttpServletRequest request,
         HttpServletResponse response) throws Exception {

       Restaurant restaurant = restaurantDAO.findRestaurantById(id);
       ModelMap modelMap = new ModelMap();
       modelMap.addAttribute("restaurant", restaurant);
       return new ModelAndView("restaurant", modelMap);
    }
}
Run Code Online (Sandbox Code Playgroud)

我的jsp只是:

<c:out value="${restaurant.name }"
Run Code Online (Sandbox Code Playgroud)

在我的spring-servlet.xml中:

<bean name="/restaurant/**" class="web.RestaurantController" >
<property name="restaurantDAO" ref="myRestaurantDAO"/> 
</bean>
Run Code Online (Sandbox Code Playgroud)

spring spring-mvc

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

Tapestry5:没有服务实现org.springframework.context.ApplicationContext接口

我使用带有spring和hibernate的tapestry 5,我尝试构建我的应用程序抛出我的这个异常??? !!! ???什么是问题,任何建议都会是这样的relif ????

[WARNING] Some problems were encountered while building the effective model for com.fit:rent-a-car:war:1.0.0-SNAPSHOT
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ line 194, column 18
[WARNING] 'reporting.plugins.plugin.version' for org.apache.maven.plugins:maven-surefire-plugin is missing. @ line 235, column 17
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
.....
.....

[ERROR] ioc.Registry No service implements …
Run Code Online (Sandbox Code Playgroud)

java tapestry spring-mvc maven-plugin

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