小编Ani*_*rni的帖子

EL中的字符串连接

我想在EL(表达式语言)中连接三元运算符中的字符串.

假设有一个名为value的变量.如果它是空的,我想使用一些默认文本.否则,我需要附加一些静态文本.

${(empty value)? "none" : value + " enabled"}
Run Code Online (Sandbox Code Playgroud)

但是这不会编译.写这个的正确方法是什么?或者这甚至可能吗?

java string jsp jstl el

56
推荐指数
4
解决办法
9万
查看次数

了解Spring MVC的@RequestMapping POST如何工作

我有一个简单的控制器,如下所示: -

@Controller
@RequestMapping(value = "/groups")
public class GroupsController {
    // mapping #1
    @RequestMapping(method = RequestMethod.GET)
    public String main(@ModelAttribute GroupForm groupForm, Model model) {
        ...
    }

    // mapping #2
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public String changeGroup(@PathVariable Long id, @ModelAttribute GroupForm groupForm, Model model) {
        ...
    }

    // mapping #3
    @RequestMapping(method = RequestMethod.POST)
    public String save(@Valid @ModelAttribute GroupForm groupForm, BindingResult bindingResult, Model model) {
        ...
    }
}
Run Code Online (Sandbox Code Playgroud)

基本上,此页面具有以下功能: -

  • 用户访问主页面(/groups GET).
  • 用户创建新组(/groups POST)或选择特定组(/groups/1 GET …

java spring spring-mvc request-mapping

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

访问scriptlet中的jstl变量

以下代码导致错误:

       <c:set var="test" value="test1"/>
      <%
        String resp = "abc"; 
        resp = resp + ${test};  //in this line I got an  Exception.
        out.println(resp);
       %>
Run Code Online (Sandbox Code Playgroud)

我不是在scriptlet.why中使用表达式语言"$ {test}"吗?

jsp jstl el scriptlet

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

找到Spring mvc Ambiguous mapping.无法映射控制器bean方法

我正在尝试构建一个应用程序,它可以列出数据库中的一些值,并在必要时使用Spring 4修改,添加,删除,并且我收到以下错误(仅当我的两个控制器文件中都存在"@Controller"注释时,如果我从其中一个文件中删除注释,但我在控制台中收到一条消息"没有找到映射...在带有名称的dispatcherservlet中......":

    INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/edit/{id}],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.bookReview.app.BookController.editBook(int,org.springframework.ui.Model)
WARN : org.springframework.web.context.support.XmlWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0': Invocation of init method failed; nested exception is java.lang.IllegalStateException: Ambiguous mapping found. Cannot map 'reviewController' bean method 
public java.lang.String com.bookReview.app.ReviewController.editReview(int,org.springframework.ui.Model)
to {[/edit/{id}],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}: There is already 'bookController' bean method
public java.lang.String com.bookReview.app.BookController.editBook(int,org.springframework.ui.Model) mapped.
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755) …
Run Code Online (Sandbox Code Playgroud)

java spring mv maven request-mapping

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

我提交spark job时可以为python代码添加参数吗?

我正在尝试用来spark-submit在spark集群中执行我的python代码.

通常我们spark-submit使用如下的python代码运行.

# Run a Python application on a cluster
./bin/spark-submit \
  --master spark://207.184.161.138:7077 \
  my_python_code.py \
  1000
Run Code Online (Sandbox Code Playgroud)

但我想my_python_code.py通过传递几个参数来运行是否有聪明的方法来传递参数?

python apache-spark cluster-mode

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

Spring MVC引用RequestMapping中的params变量

我有以下方法:

@RequestMapping(value = "/path/to/{iconId}", params="size={iconSize}", method = RequestMethod.GET)
public void webletIconData(@PathVariable String iconId, @PathVariable String iconSize, HttpServletResponse response) throws IOException {
    // Implementation here
}
Run Code Online (Sandbox Code Playgroud)

我知道如何使用@PathVariable从RequestMapping传递变量"webletId",但是如何从params引用变量"iconSize"?

非常感谢.

java spring servlets spring-mvc request-mapping

23
推荐指数
2
解决办法
6万
查看次数

请求参数的自定义Spring注释

我想编写自定义注释,根据注释修改Spring请求或路径参数.例如,而不是这段代码:

@RequestMapping(method = RequestMethod.GET)
public String test(@RequestParam("title") String text) {
   text = text.toUpperCase();
   System.out.println(text);
   return "form";
}
Run Code Online (Sandbox Code Playgroud)

我可以制作注释@UpperCase:

@RequestMapping(method = RequestMethod.GET)
   public String test(@RequestParam("title") @UpperCase String text) {
   System.out.println(text);
   return "form";
}
Run Code Online (Sandbox Code Playgroud)

它是否可能,如果是,我怎么能这样做?

java spring spring-mvc spring-annotations request-mapping

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

Spring MVC:RequestMapping类和方法

这可能吗?

@Controller
@RequestMapping("/login")
public class LoginController {

    @RequestMapping("/")
    public String loginRoot() {
        return "login";
    }

    @RequestMapping(value="/error", method=RequestMethod.GET)
    public String loginError() {
        return "login-error";
    }

}
Run Code Online (Sandbox Code Playgroud)

我在访问时遇到404错误,localhost:8080/projectname/login但没有localhost:8080/projectname/login/error.

这是我的web.xml项目名称

<listener>
    <listener-class>
        org.springframework.web.context.ContextLoaderListener
    </listener-class>
</listener>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>

<servlet>
    <description></description>
    <servlet-name>projectname</servlet-name>
    <servlet-class>
        org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>projectname</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>
Run Code Online (Sandbox Code Playgroud)

java spring spring-mvc request-mapping

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

Spring @RequestMapping

我在春天value = "/redirect/{id}"@RequestMapping注释中一直看到这种格拉姆.我一直想知道{id}这里有什么?这是某种Expression Language吗?

我看到的示例代码:

@RequestMapping( value = "/files/{id}", method = RequestMethod.GET )
public void getFile( @PathVariable( "id" )
String fileName, HttpServletResponse response )
{
    try
    {
         // get your file as InputStream
         InputStream is = new FileInputStream("/pathToFile/"+ fileName);
         // copy it to response's OutputStream
         IOUtils.copy( is, response.getOutputStream() );
         response.flushBuffer();
    }
    catch( IOException ex )
    {
         throw new RuntimeException( "IOError writing file to output stream" );
    }

}
Run Code Online (Sandbox Code Playgroud)

我的问题是{id}映射中的内容是什么,它与@PathVariable …

java spring spring-mvc request-mapping

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

如何从一个servlet文件调用另一个servlet文件?

我正在使用net beans 7.1,我创建了一个带有两个servlet文件的JSP文件.喜欢

index.jsp ---> servlet1.java ---> servlet2.java

我从index.jsp文件中提供一些价值并发送给servlet1.java.

在这个servlet1.java文件中我调用servlet2.java文件.

然后它抛出NullPointerException.
我怎么解决这个问题?

我的代码是这样的.

的index.jsp

<form  action="servlet1" method="post">  
Run Code Online (Sandbox Code Playgroud)

servlet1.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

                              ..................
                              ..................
                              ..................
        servlet2 ob=new servlet2();
        ob.doPost(request, response);
                              ..................
                              ..................
                              ..................
       }
Run Code Online (Sandbox Code Playgroud)

然后它抛出NullPointerException.

java jsp servlets nullpointerexception

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