Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Problem in using javascript in spring web mvc system:

 
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

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—

<web-app>
…………………………………………..
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>redirect.jsp</welcome-file>
</welcome-file-list>
</web-app>



dispatcher-servlet.xml contains –

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

<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">
<value>/WEB-INF/jsp/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>


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



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.*;
@SuppressWarnings("deprecation")
public class GetValueController extends SimpleFormController{
public GetValueController(){
setCommandClass(User.class);
setCommandName("user");
}
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" %>
<head>
<link rel="stylesheet" type="text/css" href="All.css" />
</head>
<body>
<div class="third">
<h3>SUBSCRIBER INFORMATION </h3>
<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();"/>
</form:form>
</div>
</body>
</html>


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

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

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

First Name: ${abc.firstName}

Last Name: ${abc.lastName}
</body>
</html>


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";
document.createSubscriberForm.submit();
}



But it didn’t help me
Please suggest what changes I will have to do .
Thanks in advance
 
Abhra Kar
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hello Any suggestion ?
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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.

Mark
 
Abhra Kar
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
thanks for the suggestion I have posted this prob in javascript forum.
 
    Bookmark Topic Watch Topic
  • New Topic