It's not a secret anymore!
The moose likes Spring and the fly likes Problem in using javascript in spring web mvc system: Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Frameworks » Spring
Reply locked New topic

Problem in using javascript in spring web mvc system:

Abhra Kar
Ranch Hand

Joined: May 22, 2008
Posts: 142

Hi I have an application “myproj5”.I am giving the entire structure of it so it will be properly understandable ,then I will say what is my requirement .

In myproj5 dir I have a redirect.jsp which contains -----
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<% response.sendRedirect("welcome.htm"); %>

In WEB-INF , web.xml contains—
<servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class>

dispatcher-servlet.xml contains –
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""

<bean id="user" class="model.User" />
<bean id="userValidator" class="validator.UserValidator" />
<bean id="viewResolver"
class=" org.springframework.web.servlet.view.InternalResourceViewResolver" >
<property name="prefix">
<property name="suffix">

<bean name="/welcome.htm" class="control.GetValueController" >
<property name="formView" value="index" />
<property name="validator"> <ref bean="userValidator"/></property>

GetValueController calss contains-----

package control;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;
import org.springframework.validation.BindException;
import model.*;
public class GetValueController extends SimpleFormController{
public GetValueController(){
protected ModelAndView onSubmit(HttpServletRequest request,
HttpServletResponse response, Object command, BindException errors)
throws Exception {
User user = (User)command;

return new ModelAndView("result","abc",user);


In WEB-INF/jsp index.jsp contains -------

<%@ taglib prefix="form" uri="/WEB-INF/spring-form.tld" %>
<link rel="stylesheet" type="text/css" href="All.css" />
<div class="third">
<form:form method="POST" commandName="user" name="createSubscriberForm">
<h3> First Name</h3>

<form:errors path="firstName" />
<form:input path="firstName" />
<h3>Last Name </h3>

<form:errors path="lastName" />
<form:input path="lastName" />

<input type="submit" value="+" onclick="javascript:requestOpenCredentialForm();"/>

In WEB-INF/jsp result.jsp contains -------
<%@ page isELIgnored="false" %>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Welcome Page</title>
<%= ((model.User)request.getAttribute("abc")).getFirstName() %>

<%= ((model.User)request.getAttribute("abc")).getLastName() %>

First Name: ${abc.firstName}

Last Name: ${abc.lastName}

So here I put some value in “index.jsp” and get those value in “result.jsp” using spring web mvc.
Now the requirement is when I will click the submit button in “index.jsp” a new window will open ,that new window will call a jsp in which some input field will be present , which I will fill up. But the the class “User”(whose user id is “user”) should be populated by the value put in index.jsp.

** After putting some value in index.jsp , the application flow will not move to “result.jsp”, it will open a new window.
How I will do it ?

I tried to do onething that, I put this code in index.jsp
<input type="submit" value="+" onclick="javascript:requestOpenCredentialForm();"/>
And put this line into <head> </head>---
<script type="text/javascript" src="xxx.js"></script>

And in xxx.js contains -----
function requestOpenCredentialForm() {
document.createSubscriberForm.action = "welcome.html"?commandName="user";

But it didn’t help me
Please suggest what changes I will have to do .
Thanks in advance
Abhra Kar
Ranch Hand

Joined: May 22, 2008
Posts: 142
Hello Any suggestion ?
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17271

I doubt, not positive, but doubt this is a Spring MVC issue.

I can move this thread to the Javascript forum, but you will have to change the title. I think there is lots of Spring stuff in your post, that they might not see that it could be a JavaScript issue. I am not a JavaScript guy, but I thought for a submit like that to work you have to return true from your JavaScript function.


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Abhra Kar
Ranch Hand

Joined: May 22, 2008
Posts: 142
thanks for the suggestion I have posted this prob in javascript forum.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: Problem in using javascript in spring web mvc system:
It's not a secret anymore!