Question

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
        <%@ taglib prefix="core" uri="http://java.sun.com/jsp/jstl/core"%>
        <%@ page import="java.util.List" %>
        <%@ page import="java.util.Iterator" %>
        <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%> 
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>login manual</title>
    <style type="text/css">


    </style>

    </head>
    <body>

    <a href="loginform.html">Back</a>


    <script type="text/javascript">

         window.onload = function()
         {
             //var opt = document.getElementById("ch").options[0];
            // opt.text="";
             //opt.value="";

         };

    </script>



        <div id="body">
         <div id="head">
             <h1>Extramark @ school</h1>


         </div>
         <form:form action="loginsuccess.html" commandName="loginSuccess" >
         <div id="choose">
                 <table>
                         <tr>
                             <td>Class</td>
                             <td><form:select path="std" id="ch" name="ch" onchange="choose()">
                             <option value="VI">VI</option>
                             <option value="VII">VII</option>
                             <option value="VIII">VIII</option>
                             <option value="X" >X</option>
                             <option value="XI" >XI</option>
                             <option value="XII" >XII</option>


                             </form:select></td>
                         </tr>

                 </table>

                 <table>
                         <tr>
                             <td>Subject</td>
                             <td><form:select path="subject" id="subselect">
                             <option id="s1" value=""></option>
                             <option></option>
                             <option></option>
                             <option></option>
                             <option></option>
                             <option></option>


                             </form:select></td>
                         </tr>

                 </table>
                 <div>

                         <input type="submit" value="Submit">
                 </div>


         </div>
         </form:form>

         <script type="text/javascript">

                     function choose()
                     {


                         var sch = document.getElementById("ch").value;

                         if(sch=="VI")
                             {

                                     var opt = document.getElementById("subselect").options[0];
                                     opt.text="maths";
                                     opt.value="maths";

                                     var opt = document.getElementById("subselect").options[1];
                                     opt.text="science";
                                     opt.value="science";

                                     var opt = document.getElementById("subselect").options[2];
                                     opt.text="physcics";
                                     opt.value="physcics";
                             }
                          if(sch=="VII")
                             {


                                     var opt = document.getElementById("subselect").options[0];
                                     opt.text="English";
                                     opt.value="English";

                                     var opt = document.getElementById("subselect").options[1];
                                     opt.text="social science";
                                     opt.value="social science";

                                     var opt = document.getElementById("subselect").options[2];
                                     opt.text="tamil";
                                     opt.value="tamil";

                             }

                          if(sch=="VIII")
                             {

                                     var opt = document.getElementById("subselect").options[0];
                                     opt.text="Computer science";
                                     opt.value="Computer science";

                                     var opt = document.getElementById("subselect").options[1];
                                     opt.text="science";
                                     opt.value="science";

                                     var opt = document.getElementById("subselect").options[2];
                                     opt.text="physcics";
                                     opt.value="physcics";
                             }


                          if(sch=="X")
                             {


                                     var opt = document.getElementById("subselect").options[0];
                                     opt.text="physcics";
                                     opt.value="physcics";

                                     var opt = document.getElementById("subselect").options[1];
                                     opt.text="science";
                                     opt.value="science";

                                     var opt = document.getElementById("subselect").options[2];
                                     opt.text="Computer science";
                                     opt.value="Computer science";

                             }


                          if(sch=="XI")
                             {


                                     var opt = document.getElementById("subselect").options[0];
                                     opt.text="tamil";
                                     opt.value="tamil";

                                     var opt = document.getElementById("subselect").options[1];
                                     opt.text="science";
                                     opt.value="science";

                                     var opt = document.getElementById("subselect").options[2];
                                     opt.text="Computer science";
                                     opt.value="Computer science";
                             }



                          if(sch=="XII")
                             {


                                     var opt = document.getElementById("subselect").options[0];
                                     opt.text="malayalam";
                                     opt.value="malayalam";

                                     var opt = document.getElementById("subselect").options[1];
                                     opt.text="science";
                                     opt.value="science";

                                     var opt = document.getElementById("subselect").options[2];
                                     opt.text="Computer science";
                                     opt.value="Computer science";
                             }
                     }

         </script>


        </div>    






    </body>
    </html>



package net.devmanuals.controllers;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.validation.BindingResult;
import java.util.Map;
import javax.validation.Valid;
import javax.validation.constraints.Size;
import org.hibernate.validator.constraints.NotEmpty;

class LoginSuccess
{
    @NotEmpty
    @Size(min = 1, max = 50)
    private String stn;
    @NotEmpty
    @Size(min = 1, max = 20)
    private String subject;
    public void setStd(String stn) 
    {
    this.stn = stn;
    }

    public String getStd()
    {
    return stn;
    }

    public void setSubject(String subject)
    {
    this.subject = subject;
    }

    public String getSubject() 
    {
    return subject;
    }
}
@Controller
@RequestMapping("loginsuccess.html")
public class SubjectVerification 
{
@RequestMapping(method=RequestMethod.GET)
public String showForm(Map model)
{
    LoginSuccess loginSuccess=new LoginSuccess();
    model.put("loginSuccess", loginSuccess);

//  System.out.println(""+loginSuccess.getStd());
    //System.out.println(""+loginSuccess.getSubject());

    System.out.println("hello");
    return "loginsuccess";

}
@RequestMapping(method=RequestMethod.POST)
public String processForm(@Valid LoginSuccess loginSuccess,BindingResult result,Map model)
{
    System.out.println("hello world");
    String stn="VI";
    String subject="maths";
    loginSuccess=(LoginSuccess)model.get("loginSuccess");

    if(loginSuccess.getStd().equals(stn)&&loginSuccess.getSubject().equals(subject))
    {
        return "maths";
    }
    model.put("loginSuccess",loginSuccess);
    return "loginform";
}

}

In the above codes i used for get the selected item value from jsp to java spring. but i cant get the values from jsp file. it displays null value. so how can i change it. and give me the suggestion for get the selected values from select box to java program

Thanks in advance

Était-ce utile?

La solution

Change the character set to unicode and try

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top