• Post Reply 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Unable to run the application

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

I am unable to run the application on Spring MVC. In Spring MVC, I have the following controller class.
package training.spring.annotation;

import javax.validation.Valid;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class AddUserFormController {

@RequestMapping(value = "/AddUser", method = RequestMethod.GET)
public String showForm(Model model) {
model.addAttribute(new User());
return "addUser";
}

@RequestMapping(value = "/ProcessUser")
public String processForm(@Valid User user, BindingResult bindingResult) {
System.out.println("in process user");
System.out.println(bindingResult.hasErrors());
System.out.println(user.getUsername() + " " + user.getPassword());
if (bindingResult.hasErrors()) {
return "addUser";
}
else {
// some logic to persist user
return "success";
}
}
}






The following is the web.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

<display-name>SpringMVCAnnotation</display-name>

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

<servlet-mapping>
<servlet-name>basicspring</servlet-name>
<url-pattern>*.obj</url-pattern>
</servlet-mapping>




<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>





The following is the basicspring-servlet.xml file:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

<context:component-scan base-package="training.spring.annotation" />
<mvc:annotation-driven/>

<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass">
<value>org.springframework.web.servlet.view.JstlView</value>
</property>
<property name="prefix">
<value>/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>

</beans>






the following is the content of addUser.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="sf" uri="http://www.springframework.org/tags/form"%>
<div>
<h2>Create a User</h2>
<sf:form method="GET" modelAttribute="user" action="http://localhost:8080/MVCTest1/ProcessUser.obj" >
<fieldset>
<sf:label path="username">Username:</sf:label> <sf:input path="username" size="15" maxlength="15" /> <small id="username_msg">No spaces, please.</small> <sf:errors path="username" />
<sf:label path="password">Password:</sf:label> <sf:password path="password" size="30" showPassword="true"/> <small>6 characters or more (be tricky!)</small>
<sf:errors path="password" />
<sf:label path="email">Email Address:</sf:label> <sf:input path="email" size="30"/> <small>In case you forget something</small>
<sf:errors path="email" />
<input name="commit" type="submit" value="Save User" />

</fieldset>
</sf:form></div>





I am unable to get the output? Can you help me out?


Thanks,
Padma priya N.G.
 
Ranch Hand
Posts: 277
Oracle Spring Flex
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Show us the Exception that you are getting.
 
Padma priya Gururajan
Ranch Hand
Posts: 437
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

On the browser, I get the following message:
The requested resource (/MVCAnno/AddUser.obj) is not available.
(MVCAnno is the context root of the application)

Thanks,
Padma priya N.G.
 
Ashwin Sridhar
Ranch Hand
Posts: 277
Oracle Spring Flex
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which file do you try to run on the server ? I don't find any file by name Adduser.obj here.
Also please used code tag in order to enclose your codings, for better readability
 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Padma,

Please edit your original post to Use Code Tags. It becomes very hard to read otherwise and you are less likely to get responses.
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try to send clear code and what are teh eceptions your getting clearly . otherwise just do copy and paste
 
Police line, do not cross. Well, this tiny ad can go through:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic