如何在html和amp;之间导航春天的jsp页面

时间:2014-10-19 06:37:46

标签: java html spring jsp spring-mvc

folder structure我在WEB-INF目录中有一个名为kind.html的Html页面,在WEB-INF文件夹中有另一个名为registration.jsp的jsp页面。我需要将此registration.jsp页面放在WEB-INF目录中,以便在用户尝试通过键入其URL来访问它时无法访问它。所以我的问题是我如何从kind.html导航到registration.jsp与链接称为家我是新手在这谢谢你。 下面是我的代码片段和png文件

kind.html ............................................ ..

<li class='active'><a href='kind.html'><span>Home</span></a></li>
<li class='has-sub'><a href="registration.jsp"><span>Register</span></a>


.............................registrationcontroller........................................
@RequestMapping(value="/registration",method = RequestMethod.POST)
    public @ResponseBody
    String firstRegistration(HttpServletRequest req,
            HttpServletResponse response) {
        response.setContentType("text/html");

        RegistrationModel registrationModel = new RegistrationModel();
        registrationModel.setFirstName(req.getParameter("first_name"));
        System.out.println("controller " + req.getParameter("first_name") );
        registrationModel.setLastName(req.getParameter("last_name"));
        registrationModel.setPassword(req.getParameter("password"));
        registrationModel.setEmailID(req.getParameter("email"));
        System.out.println("controller email " + req.getParameter("email"));
        SimpleDateFormat format = new SimpleDateFormat("yyyy-mm-dd");
        try {
            Date date = format.parse(req.getParameter("BirthDate"));
            registrationModel.setDOB(date);
        } catch (Exception e) {
            e.printStackTrace();
        }
        String phoneno=req.getParameter("phoneNo");
        Integer phoneNo = Integer.parseInt(phoneno);
        System.out.println("phone no ...."+phoneNo);
        registrationModel.setPhoneNo(phoneNo);
        registrationModel.setGender(req.getParameter("gender"));
        String age=req.getParameter("Age");
        Long AGE = Long.parseLong(age);
        registrationModel.setAge(AGE);
        registrationModel.setAvtar(req.getParameter("Avtar"));
        System.out.println("avtar"+ req.getParameter("Avtar"));

        Address address = new Address();
        address.setAddressline(req.getParameter("Full-Address"));
        address.setCity(req.getParameter("city"));
        address.setLandmark(req.getParameter("landmark"));
        address.setState(req.getParameter("state"));
        String zipCode =req.getParameter("Zipcode");
        Long zipcode = Long.parseLong(zipCode);
        address.setZipcode(zipcode);
        registrationModel.setAddress(address);

        registrationService.resgistration(registrationModel);

        return "registration.jsp";

    }

..........................registration.jsp.........................................................
<form action="registration" method="post">
                        <fieldset>
                            <legend>Register Form</legend>
                            <div>
                                <input type="text" name="first_name" placeholder="First Name" />
                            </div>
                            <div>
                                <input type="text" name="last_name" placeholder="Last Name" />
                            </div>
                            <div>
                                <input type="password" name="password" placeholder="Password" />
                            </div>
                            <div>
                                <input type="text" name="email" placeholder="Email" />
                            </div>
                            <div>
                                <input type="text" name="BirthDate" placeholder="BirthDate" />
                            </div>
                            <div>
                                <input type="number" name="Age" placeholder="Age" />
                            </div>
                            <div>
                                <select name="gender">
                                    <option value="select">i am..</option>
                                    <option value="m">Male</option>
                                    <option value="f">Female</option>
                                </select><br> <br>

                            </div>
                            <div>
                                <input type="number" name="phoneNo" placeholder="PhoneNo" />
                            </div>
                            <div>
                                <input type="text" name="Full-Address"
                                    placeholder="Full-Address" />
                            </div>
                            <div>
                                <input type="text" name="landmark" placeholder="landmark" />
                            </div>
                            <div>
                                <input type="text" name="city" placeholder="city" />
                            </div>
                            <div>
                                <input type="text" name="state" placeholder="state" />
                            </div>
                            <div>
                                <input type="number" name="Zipcode" placeholder="Zipcode" />
                            </div>
                            <div>
                                <input type="file" name="Avtar" placeholder="Avtar" />
                            </div>
                            <input type="submit" name="submit" value="Send" />
                        </fieldset>
                    </form>![folder structure of project][2]

1 个答案:

答案 0 :(得分:0)

第1次调用你的页面html是静态的,所以你可以使用mvc资源&#34;&#34;对于它,对于jsp,你必须使用ViewResolver for jstl在其配置中使用InternalResourceViewResolver:

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

然后在你的控制器中使用

return "registration";

您还需要方法来处理GET请求并在行下面进行更改

<li class='has-sub'><a href="registration"><span>Register</span></a>

如果你使用Spring启动,你会发现这些配置是自动的。