0% found this document useful (0 votes)
8 views12 pages

Advance Java Exp 7 Full

This document describes a simple Spring MVC project that allows users to input a username, which is then processed by the server to generate a response page displaying the username. It includes configuration files such as pom.xml, web.xml, and example-servlet.xml, as well as Java classes like HomeController and Service. The project uses Spring version 4.3.13, JDK 11, and Maven 4.0, and consists of JSP pages for user interaction.

Uploaded by

leonardmark017
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views12 pages

Advance Java Exp 7 Full

This document describes a simple Spring MVC project that allows users to input a username, which is then processed by the server to generate a response page displaying the username. It includes configuration files such as pom.xml, web.xml, and example-servlet.xml, as well as Java classes like HomeController and Service. The project uses Spring version 4.3.13, JDK 11, and Maven 4.0, and consists of JSP pages for user interaction.

Uploaded by

leonardmark017
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

EXP 7

This is a simple Spring MVC project where client can enter username
and then rquest goes to the server and server generate the new
response page for client. Where user input username shows.

Spring version- 4.3.13


JDK-11
Maven - 4.0
javax.servlet - 2.5
Pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mapping</groupId>
<artifactId>springweb</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>springweb Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.13.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->

<!-- https://mvnrepository.com/artifact/javax.servlet/servlet-api -->


<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>springweb</finalName>
</build>
</project>

web.xml

<!DOCTYPE web-app PUBLIC


"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<servlet>
<servlet-name>example</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</
servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>example</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

</web-app>

example-servlet.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"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">

<context:component-scan base-package="com.example"/>

<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResol
ver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix">
<value>/WEB-INF/pages/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>

HomeController.java

package com.example;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
/*
* Author AMRA
*/

@Controller
public class HomeController {

@RequestMapping("/")
public String displayt() {
return "nameView";
}

@RequestMapping("/hello")
public String helloView(Model m, @RequestParam("user") String
username) {

m.addAttribute("name", username);
return "helloView";
}
}
IService.java

package com.example.service;

/*
* Author AMRA
*/

public interface IService {

public void orderPizza();


public void generaeBill();

}
Service.java

package com.example.service;

/*
* Author AMRA
*/

public class Service implements IService{

public void orderPizza() {


// TODO Auto-generated method stub

public void generaeBill() {


// TODO Auto-generated method stub

}
nameView.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-


1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>NameView</title>
</head>
<body>
<h2>welcome page</h2>
<form action="hello">
UserName : <input type="text" name="user"/>
<br><br> <input type="submit" value="submit">
</form>
</body>
</html>
helloView.jsp

<html>
<body>
<h2>Hello <%= request.getAttribute("name") %></h2>
</body>
</html>

OUTPUT

You might also like