Skip to content

Instantly share code, notes, and snippets.

@izzuddin91
Created November 30, 2017 09:36
Show Gist options
  • Select an option

  • Save izzuddin91/7dccdf8dbed493ce279d0c21c2cb02bf to your computer and use it in GitHub Desktop.

Select an option

Save izzuddin91/7dccdf8dbed493ce279d0c21c2cb02bf to your computer and use it in GitHub Desktop.
example of passing data without Model (spring)
<!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<html>
<head>
<meta charset="utf-8">
<title>Welcome</title>
</head>
<body>
<h1>Welcome to Etiqa AutoClaim webpage</h1>
<span>Please key your email and password</span> <br>
<c:url value="/showMessage" var="messageUrl"/> <br>
<c:url value="/testIzzuddin" var="messageUrl2" /> <br>
<form:form action="${messageUrl}" id="test" method="post">
<input type="text" name="userid"/>
<input type="submit"/>
</form:form>
<a href="${messageUrl}">Click to enter</a>
<a href="${messageUrl2}">Click to enasdasdter</a>
</body>
</html>
package com.spring.test;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
@Controller
public class TestController {
@RequestMapping(value = "/", method = RequestMethod.GET)
public String home(Locale locale, Model model) throws IllegalArgumentException, IOException {
System.out.println("Default method");
Date date = new Date();
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
String formattedDate = dateFormat.format(date);
try {
String dirToPython = new String("D:\\Python3.6.3\\Python36\\python ");
String pythonScript = new String("D:\\Python3.6.3\\Python36\\classify.py ");
String dirToImage = new String("D:\\Python3.6.3\\Python36\\crack1.jpg ");
String dirToImage2 = new String("\"https://www.thesun.co.uk/wp-content/uploads/2017/03/nintchdbpict000311936030.jpg\"");
String trainingLabels = new String("D:\\Python3.6.3\\Python36\\trained_labels.txt ");
String trainingGraph = new String("D:\\Python3.6.3\\Python36\\trained_graph.pb");
Process q = Runtime.getRuntime().exec(dirToPython + pythonScript + dirToImage + " D:\\Python3.6.3\\Python36\\logs\\trained_labels.txt D:\\Python3.6.3\\Python36\\logs\\trained_graph.pb");
final int exitVal = q.waitFor();
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(q.getInputStream()));
System.out.println(stdInput.readLine() );
} catch (Exception e) {
e.printStackTrace();
}
model.addAttribute("serverTime", formattedDate );
return "index";
}
@RequestMapping(value = "/showMessage", method = RequestMethod.POST)
//focus on that @RequestMapping, compulsory
public String showMessage(Locale locale, Model model, @RequestParam("userid") String username) {
System.out.println(username);
Date date = new Date();
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
String formattedDate = dateFormat.format(date);
model.addAttribute("message", username);
return "showMessage";
}
//ignore this one below
@RequestMapping(value = "testIzzuddin", method = RequestMethod.GET)
public String testIzzuddin(Locale locale, Model model) {
Date date = new Date();
DateFormat dateformat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
String formattedDate = dateformat.format(date);
String testString = "test string";
model.addAttribute("message", testString);
model.addAttribute("date", formattedDate);
return "testIzzuddin";
}
}
<!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<head>
<meta charset="utf-8">
<title>Welcome </title>
</head>
<body>
<h2>${message}</h2>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment